WHAT IS SERVLETCONTEXT OBJECT?

Kamlakar Singh

Total Post:80

Points:400
Posted by  Kamlakar Singh
 918  View(s)
Ratings:
Rate this:
  1. Kamlakar Singh

    Post:80

    Points:400
    What is ServletContext object?

    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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!