Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is the difference between ServletContext and ServletConfig

 
Mahendran Aiyappan
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Naresh Waswani
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mahendran Aiyappan
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Naresh Waswani
 
Mahendran Aiyappan
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Mr krisp prasad
 
kalpana kp
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Bear edit: thread hi-jack removed]
[ September 07, 2006: Message edited by: Bear Bibeault ]
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic