ServletConfig
ServletConfig is use to initialize a servlet. Its scope is within the servlet i.e.,when servlet starts executing, ServletConfig object will be available until execution of servlet is completed. For a particular servlet, there is only one ServletConfig object. getServletConfig() method is used to get the ServletConfig object.
Example:
<servlet>
<servlet-name>DemoServlet</servlet-name>
<servlet-class>DemoServlet</servlet-class>
<init-param>
<param-name>name</param-name>
<param-value>garry</param-value>
</init-param>
</servlet>
ServletContext
ServletContext helps to communicate between servlet container and all of its servlet. Its scope is within the web application (it is common for all the servlet) i.e., ServletContext object will be available until the execution of web application is completed, and its object will be destroyed once web aaplication remove from server. getServletContext() method is used to get the ServletContext object.
Example:
<context-param>
<param-name>dbdriver</param-name>
<param-value>com.mysql.jdbc.Driver</param-value>
</context-param>
0 Comment(s)