wea sels wrote:Hi,
my question is ServletConfig and ServletContext are interfaces implemented by GenericServlet and HttpServlet classes so how can they have objects?
Like
ServletConfig config;
ServletContext context;
[Answer1] config/ context are the objects and are type casted to ServletConfig/ ServletContext which java permits
if they are interface references how can they be passed as objects
example : super.init(config);
[Answer2] Answers1 states that config/ context are the objects so perfectly legal to pass the objects
also if we use the above overriding statement
why is the following statement correct?
super.init(config);
ServletContext context=getServletContext();
what does it mean:: The ServletContext object is contained within the ServletConfig object, which the Web server provides the servlet when the servlet is initialized.
I have gone through the docs but couldnt understand so i am posting here. Thanks
wea sels wrote:Yes but what I would like to understand is ServletContext and ServletConfig are interfaces so how are config and context passed as objects??
http://www.java2s.com/Tutorial/Java/0400__Servlet/GetServletContextInitParameter.htm
soumyaansh roy wrote:what are the significance of ServletContext and ServletConfig what kind of information we save in these 2 objects please give some practical examples , thanks
Mohammad Monis wrote:
soumyaansh roy wrote:what are the significance of ServletContext and ServletConfig what kind of information we save in these 2 objects please give some practical examples , thanks
ServletConfig - parameter scope is limited to the scope of the servlet in which the parameter is defined. For example, shopping cart of a user is specific to a particular user so servletconfig params can be used.
ServletContext - parameter scope is application wide and the parameter can be use to store application session info/ application initialization parameters,etc not specific to a servlet.
No pain, No gain.
OCJP 1.6, Liferay Certified Developer 6.1
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Deepak Lal wrote:Hi,
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |