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

<servlet-name>ServletConfigTest</servlet-name>
<servlet-class>com.javapapers.ServletConfigTest</servlet-class>
<init-param>
<param-name>topic</param-name>
<param-value>XXXX</param-value>
</init-param>
</servlet>




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.
<context-param>

<param-name>globalVariable</param-name>
<param-value>javapapers.com</param-value>
</context-param>

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