ServletConfig

  • ServletConfig is an in-built interface preasent in javax.servlet.*; package
  • ServletConfig object is one per servlet class
  • ServletConfig object will be created during initialization process of the servlet
  • This object is public to a particular servlet only
  • Scope: As long as a servlet is executing, ServletConfig object will be available, it will be destroyed once the servlet execution is completed.
  • We should give request explicitly, in order to create ServletConfig object for the first time
  • In web.xml tag will be appear under tag

servlet_config

Here's how it looks under web.xml :

Example

<servlet>
<servlet-name>ServletConfigDemo</servlet-name>
<servlet-class>com.javarace.ServletConfigTest</servlet-class>
<init-param>
<param-name>topic</param-name>
<param-value>Difference between ServletConfig and ServletContext</param-value>
</init-param>
</servlet>

ServletContext

  • ServletContext interface available in javax.servlet.*; package
  • ServletContext object is global to entire web application
  • Object of ServletContext will be created at the time of web application deployment
  • Scope: As long as web application is executing, ServletContext object will be available, and it will be destroyed once the application is removed from the server.
  • ServletContext object will be available even before giving the first request In web.xml tag will be appear under tag

Here's how it looks under web.xml :

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

So finally...

No. of web applications = That many number of ServletContext objects

No. of servlet classes = That many number of ServletConfig objects

Difference between ServletContext and ServletConfig

Our Services:

Java Training | Python Training | Machine Learning with Python Training | Deep Learning with Python Training | Projects

SILAN Technology
Call to: 9439202111  |  9658317757  |  0674-2361252

Comment