Difference between servletContext and ServletConfig

ServletConfig
ServletConfig is implemented by the servlet container to initialize a single servlet using init().  you can pass initialization parameters to the servlet using the web.xml deployment descriptor. Every servlet has its own ServletConfig object.

Example code:

<servlet>
<servlet-name>ServletConfigTest</servlet-name>
<servlet-class>com.shivasoft.ServletConfigTest</servlet-class>
<init-param>
<param-name>article</param-name>
<param-value>Difference between servletContext and ServletConfig</param-value>
</init-param>
</servlet>

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.
The ServletContext object is contained within the ServletConfig object. That is, the ServletContext can be accessed using the ServletConfig object within a servlet. You can specify param-value pairs for ServletContext object in  <context-param> tags in web.xml file. ServletContext is created at the application level and shared by all the Servlet codes.

Example : Database string used by the application.

<context-param>
<param-name>dbString</param-name>
<param-value>Provider=MySQLProv;Data Source=shivasoft;User Id=shiva; Password=soft;</param-value>
</context-param>

Posted

in

by

Tags:


Related Posts

Comments

One response to “Difference between servletContext and ServletConfig”

  1. slashdot Avatar
    slashdot

    Considerably, the content is actually the finest about this significant subject. I trust your own conclusions and can thirstily look forward to the next improvements.I’ll instantly grab your own rss feed to stay up to date with any improvements.

Leave a Reply to slashdotCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading