2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

What is ServletConfig and ServletContext object in servlet?

What is ServletConfig and ServletContext object in servlet?
userimage

Every servlet has it's own ServletConfig object and servlet container is responsible for instantiating this object and ServletConfig is used to pass configuration information to Servlet. We can use getServletConfig() method to get the ServletConfig object of the servlet.


ServletContext interface provides access to web application parameters to the servlet. The ServletContext is unique object and available to all the servlets in the web application. When we want some init parameters to be available to multiple or all of the servlets in the web application, we can use ServletContext object and define parameters in web.xml using <context-param> element. We can get the ServletContext object via the getServletContext() method of ServletConfig. Servlet containers may also provide context objects that are unique to a group of servlets and which is tied to a specific portion of the URL path namespace of the host.

Answer is