java2db

Difference between ServletConfig and ServletContext



Both ServletConfig and ServletContext interfaces are from javax.servlet package.

 

ServletConfig and ServletContext differences are given below.

ServletConfig

Difference between ServletConfig and ServletContext For each servlet class , the servlet container creates one ServletConfig  object at the time of servlet class instantiation.

Difference between ServletConfig and ServletContext Servlet container supplied java class that implements javax.servlet.ServletConfig interface .

Difference between ServletConfig and ServletContext ServletConfig object is specific to a servlet, no other servlet can access this.

Difference between ServletConfig and ServletContext By using ServletConfig  object, we can get (<init-param>) values from web.xml  and current servlet details.

Difference between ServletConfig and ServletContext ServletConfig object destroys along with the servlet object (Container destroys the servlet object).

Difference between ServletConfig and ServletContext Use ServletConfig config = getServletConfig(); in servlet to get this object.

 

Example ServletConfig object diagram :

Use of ServletConfig object in servlet with an example

 

 

ServletContext

Difference between ServletConfig and ServletContextFor each web application , the container creates one ServletContext object at the time of web application deployment or at server start-up (if the web application already deployed in server).

Difference between ServletConfig and ServletContextIt is the object of servlet container class that implements javax.servlet.ServletContext interface.

Use of ServletContext object in servlet with exampleAll servlets or JSPs  from a web application can access the ServletContext object.So it is called the global memory of the web application.

Difference between ServletConfig and ServletContextUsing ServletContext object in servlet, we can read the values of <context parameter> from web.xml , possible to do filter operations and we can gather server information.

Difference between ServletConfig and ServletContextThe servlet container destroys ServletContext object when the web application is un-deployed/stopped/reloaded/.

Difference between ServletConfig and ServletContextUse ServletContext context = getServletContext(); in servlet to get this object.

 

Example ServletContext object diagram :

get the form data in servlet



Related Posts :
Servlet Filter ( Request and Response filters in servlets ) example
URL rewriting in servlets ( Servlet session tracking )
Servlet Cookies ( Servlets session tracking with cookie )
Hidden form field in servlets ( Servlet session tracking )
Request attributes in servlet with an example ( Attribute scope )
Session attributes in servlet with example (Attribute scope)
ServletConext Attributes in servlet ( Attribute scope )
The sendRedirect (servlets are in different web applications)
   [will not be published]



^ <