Tuesday, April 27, 2010

Difference between ServletConfig and ServletContext

* Signature: 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. For understanding, this is similar to a constructor in a java class.

Example code:
<-servlet>
<-servlet-name>ServletConfigTest<-/servlet-name>
<-servlet-class>com.javapapers.ServletConfigTest<-/servlet-class>
<-init-param>
<-param-name>topic<-/param-name>
<-param-value>Difference between ServletConfig and ServletContext<-/param-value>
<-/init-param>
<-/servlet>

* Signature: public interface ServletContext
ServletContext is implemented by the servlet container for all servlet to communicate with its servlet container, for example, to get the MIME type of a file, to get dispatch requests, or to write to a log file. That is to get detail about its execution environment. 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. That is, the ServletContext can be accessed using the ServletConfig object within a servlet. You can specify param-value pairs for ServletContext object in tags in web.xml file.

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

9 comments:

saranya said...

I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.
python training in rajajinagar
Python training in bangalore
Python training in usa

jai said...

Good Post, I am a big believer in posting comments on sites to let the blog writers know that they ve added something advantageous to the world wide web.
Data Science course in rajaji nagar
Data Science with Python course in chenni
Data Science course in electronic city
Data Science course in USA
Data science course in pune | Data Science Training institute in Pune

jeeva said...

I appreciate your efforts because it conveys the message of what you are trying to say. It's a great skill to make even the person who doesn't know about the subject could able to understand the subject . Your blogs are understandable and also elaborately described. I hope to read more and more interesting articles from your blog.
rpa training in bangalore
best rpa training in bangalore
rpa training in pune | rpa course in bangalore
rpa training in chennai

rohini said...

I read this post two times, I like it so much, please try to keep posting & Let me introduce other material that may be good for our community.
Best Devops Training in pune
Devops Training in Bangalore
Microsoft azure training in Bangalore
Power bi training in Chennai

jefrin said...

Good to read this blog thanks for sharing
salesforce training institute in chennai

karthick said...

You are doing a great job. I would like to appreciate your work for good accuracy

CCNA Course in Chennai

shivam said...


Top engineering colleges in India

technical news
what is microwave engineering
what is pn junction
How to Increase followers on Instagram
how to crack filmora 9
digital marketing course in bhopal

Anu said...


The article gives me a lot of interesting information. I still often share life experiences with friends. devops training in chennai | devops training in anna nagar | devops training in omr | devops training in porur | devops training in tambaram | devops training in velachery

salome said...

Informative and useful article with detailed explanation. Thanks for sharing Angular training in Chennai