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

Session v Servlet Context

 
Gagan Sabharwal
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello !!!
Since servlet is something new for me!!! I am finding some difficulties to deal with it....

How are the sessions more advantageous than servlet contexts? I wanted an illiustration as well...So,i would be really thankful if any of u guys help me out of this!!!

[Edit by Dave to give a meangful subject]
[ April 25, 2006: Message edited by: David O'Meara ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use a meaningful topic, please use real words.

A session is related to a user, so each time the user provides a request you can look at the information attached to this user. A Servlet context is attached to a Servlet, and the same servlet serves multiple users. Therefore the two are not the same.

Dave
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gagan Sabharwal:
How are the sessions more advantageous than servlet contexts?


Sessions belongs to a particular user whereas servletContext is shared by all active users. We store all user related info to the session of that particular user like, role etc. Whereas servletContext is used to store appication level information.

Session remains valid only as long as the users browser stays open and user remains active.

Edited after Bear's post
servletContext remains valid until application goes out of service.
[ April 26, 2006: Message edited by: Adeel Ansari ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64708
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to make sure that there are no misconceptions...

servletContext should have been more properly named applicationContext. There is only one servletContext for the entire web app. It is not tied to any one particluar servlet. It comes into scope when the application is started, and stays in scope until the application is stopped. The servlets themselves can come into and out of scope and the servletContext is not affected.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic