Both are interfaces :)
SevletContext
The ServletContext interface provides information to servlets regarding the environment in which they are running. ServletContext represent's your web application,so there is only one sevletContext for your application. ServletContext is a window given to a servlet to view its environment.It contains the global information,which are name/value pair.
ServletConfig
For particular servlet in your application there is one ServletConfig so,if 10 servlets are there in your application then there are 10 ServletConfigs. The servlet engine implements the ServletConfig interface in order to pass configuration information to a servlet. ServletConfig contains information(name/value pair) specific to particular servlet used during initializing servlet.
When we deploy a web application the webcontainer reads the deployment descriptor(i.e,web.xml). If there is no problem then the webcontainer creates a ServletContext object for that web-application. The webcontainer removes the ServletContext object when the web application is stopped. So the no. of ServletContext objects present in web container depends on no.of web applications present. For every web application a ServletContext object is created by web container. And WebContainer creates ServletConfig object for every servlet that is a part of web application. As part of web application there will be only one ServletContext object,but there can be multiple ServletConfig objects.
No comments:
Post a Comment