This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
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 ]
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.