ServletConfig and ServletContext

public interface ServletConfig

ServletConfig is implemented by the servlet container to initialize a single servlet using init(). That is, you can pass initialization parameters to the servlet using the web.xml deployment descriptor
 Ex.: similar to a constructor in a java class.


public interface ServletContext

ServletContext is implemented by the servlet container for all servlet to communicate with its servlet container
It is applicable only within a single Java Virtual Machine. If a web applicationa is distributed between multiple JVM this will not work. For understanding, this is like a application global variable mechanism for a single web application deployed in only one JVM.
The ServletContext object is contained within the ServletConfig object.


The ServletConfig parameters are specified for a particular servlet and are unknown to other servlets.
The ServletContext parameters are specified for an entire application outside of any particular servlet and are available to all the servlets within that application.

ServletContext has a APPLICATION SCOPE
ServletConfig has a SESSION SCOPE..