Friday, July 20, 2012

Difference between ServletContext and ServletConfig ?

What is the Difference between ServletConfig and ServletContext.?


public interface ServletConfig

ServletConfig encapsulates servlet configuration and gives access to the application (servlet context) object. Servlet initialization parameters appear in the servlet configuration file. Each servlet class may have several different servlet instances, one for each servlet parameters:

  1. One ServletConfig per servlet
  2. It is used to pass deploy-time info to servlet and configured in the deployment descriptor file. 
  3. it is used to access ServletContext 
  4. It is within the Servlet element in Deployment descriptor.
  5. It is accessed by using getServletConfig().getInitParameter("myname"); 
  6. It is available only to the servlet in which init-param is configured.



public interface ServletContext

ServletContexts encapsulate applications. Applications are generalized virtual hosts; a URL prefix defines a distinct application. So /myapp and /yourapp could define different applications. As a degenerate case, each virtual host has its own ServletContext. 

  1. It returns the current context of a web application running in a particular JVM.. 
  2. If the web application is distributed,it is one per JVM. 
  3. It is used to access the elements configured in deployment descriptor.
  4. It is accessed by using getServletContext().getInitParameter("myname"); 
  5. It is available to any servlet or jsp that is part of web application.



  1. I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

    Java Online Training Java Online Training Core Java 8 Training in Chennai java 8 online training JavaEE Training in Chennai Java EE Training in Chennai

  2. This is my first time i visit here and I found so many interesting stuff in your blog especially it's discussion, thank you. Kopar at Newton Kampong Java Road

  3. Thus, with the above features, Python training can very well act as a mentoring course to freshers. unindent does not match any outer indentation level python

  4. Wow, this is fascinating reading. I am glad I found this and got to read it. Great job on this content. I liked it a lot. Thanks for the great and unique info. Europa-Road targonca szállítás Debrecen