Difference between servletContext and 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:

<param-value>Difference between servletContext and ServletConfig</param-value>

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.

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

About Sanju
I am Software Programmer. I am working in JAVA/J2EE Technologies.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: