i'm still unclear about the differences,hence i have posted it in the forum. if you can illustrate the differences,it would be helpful.
-- Deepak Lal
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35237
7
posted
1
Why don't you try to describe how you understand them to be similar, and how you understand them to be different? Explaining something can help to clarify one's thoughts, and thus one's understanding. If you go wrong, we can jump in with comments.
Thanks all for your replies. i'm pasting the differences in case anyone wants to refer it for future --------------- ServletConfig --------------- One ServletConfig per servlet it is used to pass deploy-time info to servlet and configured in the deployment descriptor file. it is used to access ServletContext It is within the Servlet element in Deployment descriptor. It is accessed by using getServletConfig().getInitParameter("myname"); It is available only to the servlet in which init-param is configured.
-------------- ServletContext --------------- It returns the current context of a web application running in a particular JVM. if the web application is distributed,it is one per JVM. It is used to access the <context-param> elements configured in deployment descriptor. It is accessed by using getServletContext().getInitParameter("myname"); It is available to any servlet or jsp that is part of web application.
I hope the above interpretations can be used for later reference.
-- Deepak Lal
vijay karmani
Greenhorn
Joined: Feb 09, 2005
Posts: 4
posted
0
Both ServletConfig and ServletContext are configuration objects used by servlet container to initialize various init parameters for a web application. However they differ in terms of the scope and availability of init parameters defined by both of them.
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
Mohammad Monis
Greenhorn
Joined: Jan 04, 2012
Posts: 5
posted
0
ServletConfig has servlet wide scope. It is defined inside <servlet> </servelet> in web.xml
ServletContext has application wide scope . It is defined outside the <servlet> tag in web.xml
Jack Weasels
Greenhorn
Joined: Jan 04, 2012
Posts: 22
posted
0
Yes but what I would like to understand is ServletContext and ServletConfig are interfaces so how are config and context passed as objects??
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
Mohammad Monis
Greenhorn
Joined: Jan 04, 2012
Posts: 5
posted
0
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??
objects can be type cast to the implementing interface.
Jack Weasels
Greenhorn
Joined: Jan 04, 2012
Posts: 22
posted
0
thanks. that solved my doubts
soumyaansh roy
Greenhorn
Joined: Jan 05, 2012
Posts: 2
posted
0
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
Greenhorn
Joined: Jan 04, 2012
Posts: 5
posted
0
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.
soumyaansh roy
Greenhorn
Joined: Jan 05, 2012
Posts: 2
posted
1
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.
Actually the servlet container will create ServletConfig object and pass it to the servlet when it's initialized. Servlet container does object creation for other interface types HTTP request, response etc.
ServletContext: a kind of application object. Gives you the possibility to store attributes shared by all the sessions (enjoy responsibly, work thread safe)
ServletConfig: the object containing the init-param elements defined under the <servlet> tag inside the web.xml
They are different, although they sound very similar...
D.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.