What is the difference between servlet context and servlet config

Showing Answers 1 - 13 of 13 Answers

Guest

  • Jan 1st, 2006
 

 

ServletConfig is a servlet configuration object used by a servlet container used to pass information to a servlet during initialization. All of its initialization parameters can ONLY be set in deployment descriptor.

The ServletContext object is contained within the ServletConfig object, which the Web server provides the servlet when the servlet is initialized.

You can specify param-value pairs for ServletContext object in <context-param> tags in web.xml file.

The ServletConfig parameters are specified for a particular servlet and are unknown to other servlets.

The ServletContext parameters are specified for an entire application outside of any particular servlet and are available to all the servlets within that application.

  Was this answer useful?  Yes

Guest

  • Jan 19th, 2006
 

ServletConfig is a interface which is used to access initialization parameters which are initialised at the time of conifuguration the servlet into the webserver.like get init parameters .ServletContext is sharaed memory segmet for life of web application until remove explicitly . Every webapplication has its own ServletContext.serveletContext has shared by the all servlets,and jsps within one web application

  Was this answer useful?  Yes

shekar

  • Jan 26th, 2006
 

ServletConfig read the parameter values throg xml file called by the Serv letContainer.

ServletContext

  Was this answer useful?  Yes

Gopinath

  • Apr 26th, 2006
 

Both ServletConfig and ServletContext parameters are specified within the web.xml file.

ServletConfig refers to parameters which is specific to a Servlet

ServletContext refers to parameters available to an entire application.

Even in the web.xml file

the ServletConfig parameters are specified within <servlet>   </servlet> tags

whereas the ServletContext Parameters are not specified so.

Eg:- For example I want to print my E-mail address , to the request of a page from the client.Either I can HardCode the value of E-mail or I can specify it as a ServletConfig Parameter.The Advantageof specifying it as a ServletConfig Parameter is that If I would change my E-mail Id I would have to change it only in the XML file and hence retesting of the already tested servlet is not necessary.

If on the other hand I want the E-mail Id to be made available across the entire application I would specify it as ServletContext parameter.

  Was this answer useful?  Yes

sureshkumar

  • Nov 8th, 2006
 

Servlet context is called application object .There would be only one servlet context for a web application.This servlet context is used to get context parameters defined in web.xml .Apart from that it is used to get the information of servlet engine and to get the Request Dispatcher.RequestDispatcher rd=getServeltContext().getRequestDispatcher();ServletConfig:There would be one ServletConfig for each servlet.so multiple config objects exists for a webapplication because there are more number of servlets in a webapplication.This is used to get the information of servlet and to get the initparameters from web.xml

Rohit

  • Jul 22nd, 2007
 

Servlet Config parameters are set for the servlet initialization, these information is necessary for the servlet startup, eg.: Database connectivity, other xml files. etc.

Servlet Context are used by the servlets to interact with the SERVER, servlet can get all the information of the server through SERVLETCONTEXT. eg. ServletContext.getAttributes() etc.

  Was this answer useful?  Yes

style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 9pt">Servlet
Config


style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 9pt">1
Servlet config are one per servlet per JVM
2
It's inside the servlet it won’t accessible to outside the servlet.


style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 9pt">
Ex:
<servlet>
           
<init-param>
           
<param-name>


style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 9pt">           
<param-value>
           
</init-param>
</servlet>


style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 9pt">Servlet
Context


style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 9pt">1.
Servlet context is one per web application per jvm
2.
It can be accessible to all other web application
3.
Ex when you want to redirect your page in to JSP it can be possible
here.
4. ServletContext =
ServletConfig.getServletContext()


style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 9pt">Ex:
<webapp>
<context-param>
           
<param-name>
           
<param-value>
</context-param>
</webapp>


Hope this makes this a little more clear.


Thanks,
Vinay


  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions