Hi! what is the difference between ServletConfig.getInitParameter() and ServletContext.getInitParameter() ? Thank you in advance.
Stephen Tallamy
Greenhorn
Joined: Jan 08, 2002
Posts: 16
posted
0
ServletConfig contains information specific to that servlet. ServletContext contains information about the web application the servlet is a member of. Generally you use ServletContext to get global set-up parameters such as the webmaster's email addres or a central database. ServletConfig is used more for specific initalisation parameters for the servlet. Here is an example web application descriptor:
In this example, param1 is available through the ServletContext of both MyServlet and MyOtherServlet. param2 is available through the ServletConfig of MyServlet only. param3 is available through the ServletConfig of MyOtherServlet only. Hope this helps.
Rohit Poddar
Ranch Hand
Joined: Aug 18, 2001
Posts: 36
posted
0
1) ServletContext is same for all the servlets in that Web application i.e. there is only one ServletContext per Web App. per JVM. And hence ServletContext.getInitParameter() will give same parameter values to each Servlet in thar web app. ServletConfig is the object passed to Servlet by container to give initialization information (which is different for different Servlets) for that servlet as oppose to Servlet Context (which is one per Web APp per JVM) and hence ServletConfig.getInitParameter() might give different values in each servlet. 2) Servlet COntext init parameters are specified in web.xml using <context-param></context-param> tag whereas Servlet init params are specified by <servlet><init-param></init-param></servlet>