MY mENU


Saturday 17 March 2012

Difference between ServletConfig and ServletContext object ?




                ServletConfig
           
             ServletContext


ServletConfig object means it is the object of a class that implements ServletConfig interface.[ javax.servlet.ServletConfig]


Servlet context object means it is the object of a class that implements javax.servlet.ServletContext interface.

1 per servlet object so it is called right-hand object for servlet object.


It is one per web-application         

Every Servlet contains one ServletConfig object.

Common for all the web-resources of a web-application. So it is called Global memory of the web-application.


Web container creates ServletConfig object for servlet object when servlet object is created. web container destroys ServletConfig object  when its servlet object is destroyed.

web-container creates ServletContext object when web-application is deployed and destroys ServletContext  object when web-application  stopped (or)reloaded (or) undeployed.


ServletConfig object is useful to pass additional data to the servlet and to read additional data from the servlet like “logical name “ given to servlet and etc…

Using ServletContext object we can gather following details
1)Name and version of the underlying web server.
2)servlet API version implemented by web server.
3)Logical Names of all servlets available in web-application 4)”context parameters”   available in the web-application.


No comments:

Post a Comment