This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes What is the difference between ServletContext and ServletConfig Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "What is the difference between ServletContext and ServletConfig" Watch "What is the difference between ServletContext and ServletConfig" New topic
Author

What is the difference between ServletContext and ServletConfig

Mahendran Aiyappan
Ranch Hand

Joined: Sep 05, 2005
Posts: 102
Please provide me the difference between ServletContext and ServletConfig. I know that ServletContext can be application level and ServletConfig for Servlet level. But other than that what is the difference. Your replies are always welcome.


Thanks
Mahendran
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

"Mahendran",
Welcome to the JavaRanch.

We're a friendly group, but we do require members to have valid display names.

Display names must be two words: your first name, a space, then your last name. Fictitious names are not allowed.

Please edit your profile and correct your display name since accounts with display names get deleted, often without warning

Your display name was valid, now it is not. Please change it back or we will have to close your account.

thanks,
Dave
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41088
    
  43
If you read through the javadocs for the two, you'll see that they serve very different purposes. Roughly speaking, ServletContext exists one a per application, while ServletConfig exists one per servlet.


Ping & DNS - my free Android networking tools app
Naresh Waswani
Greenhorn

Joined: Jun 02, 2006
Posts: 5
generally it's a belief that there is one servletcontext per application. but in reality

this is the case when your application is running on one jvm. if your application is running on more than one jvm's than you have more than one servletcontext objects for your application (one servlet context object per jvm).

but your servlet config object is always one per servlet/jsp.

regards

Naresh waswani
9986461501
krishna prasad gunasekaran
Ranch Hand

Joined: Jul 25, 2006
Posts: 158
ServletConfig has only Parameters.
ServletContext has both Paramters and Attributes.

If you check through the ServleConfig API, you will find no setter methods. Only getter methods are available. obviously you can't set an initial parameter.

with ServletContext, you will find a setter method,
setAttribute(String string, Object o)
No setParameter() even with ServletContext.As said above parameters can't be set.

with regards,
krishna prasad


have a great day,
krishna prasad
Mahendran Aiyappan
Ranch Hand

Joined: Sep 05, 2005
Posts: 102
Thank you Naresh Waswani
Mahendran Aiyappan
Ranch Hand

Joined: Sep 05, 2005
Posts: 102
Thank you Mr krisp prasad
kalpana kp
Greenhorn

Joined: Sep 07, 2006
Posts: 12
[Bear edit: thread hi-jack removed]
[ September 07, 2006: Message edited by: Bear Bibeault ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41088
    
  43
kalpana devalla,

welcome to JavaRanch.

Please don't post questions to threads that deal with a completely different topic - start a new thread. It gets confusing if multiple subjects are part of the same thread.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: What is the difference between ServletContext and ServletConfig
 
Similar Threads
init parameters
context/config
Diff between ServletContext and servletConfig
getInitParamater() method
servletConfig and servletContext