File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Session v Servlet Context Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session v Servlet Context" Watch "Session v Servlet Context" New topic
Author

Session v Servlet Context

Gagan Sabharwal
Ranch Hand

Joined: Apr 23, 2006
Posts: 48
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

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Jan 10, 2002
Posts: 60780
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Session v Servlet Context
 
Similar Threads
Problem creating servlets in Netbeans
Servlet Context Vs Servlet Config
The requested resource is not available
Browser won't show url. Web.xml
Return to Login Page