ServletContext Interface

ServletContext Interface: An object of ServletContext is created by the web container at time of deploying the project. This object can be used to get configuration information from web.xml file. There is only one ServletContext object per web application.

If any information is shared to many servlet, it is better to provide it from the web.xml file using the<context-param> element.

There can be a lot of usage of ServletContext object. Some of them are as follows:

  1. The object of ServletContext provides an interface between the container and servlet.
  2. The ServletContext object can be used to get configuration information from the web.xml file.
  3. The ServletContext object can be used to set, get or remove attribute from the web.xml file.
  4. The ServletContext object can be used to provide inter-application communication.

Leave a Reply

Your email address will not be published. Required fields are marked *