Home > DeveloperSection > Interviews > What is ServletContext object?

Posted on    November-03-2014 11:07 PM

 ASP.Net Java  Session 
 1 Answer(s)
  631  View(s)
Rate this:

Kamlakar Singh
Kamlakar Singh

Total Post:80

Posted on    November-04-2014 12:07 AM

javax.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.

ServletContext is enhanced in Servlet Specs 3 to introduce methods through which we can programmatically add Listeners and Filters and Servlet to the application. It also provides some utility methods such as getMimeType(), getResourceAsStream() etc.

Don't want to miss updates? Please click the below button!

Follow MindStick