File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes HttpSession and ServletContext - Difference? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "HttpSession and ServletContext - Difference?" Watch "HttpSession and ServletContext - Difference?" New topic

HttpSession and ServletContext - Difference?

aatish pandya

Joined: Apr 20, 2011
Posts: 21
I am unable to store a LinkedList in an HttpSession but can do with a ServletContext. why? what is the difference between the two?
srinivas srinivasmeenavalli
Ranch Hand

Joined: Jul 13, 2008
Posts: 65
What is the issue while stroring Linked list in HttpSession? Why you want to store in a session.
Session - values store with in a User session scope
ServletContext - Values store with in a servlet scope
Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 1341

@Aatish - please post exact error/exception that you are facing while saving LinkedList in HTTPSession.

A very wild guess from my side -- are you facing NotSerializableException? if yes then please read on..
If your applicaion is clustered one (distributed), then all objects, which are supposed to be stored in HTTPSession, must implements Serializable interface. If you do not implement Serializable interface , then, notSerializableException is thrown. Below mentioned are the two old posts referring to same error

~ abhay
I agree. Here's the link:
subject: HttpSession and ServletContext - Difference?
It's not a secret anymore!