*
The moose likes Servlets and the fly likes Do HttpSession attributes store references or entire objects? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Do HttpSession attributes store references or entire objects?" Watch "Do HttpSession attributes store references or entire objects?" New topic
Author

Do HttpSession attributes store references or entire objects?

Tommy Sedin
Greenhorn

Joined: Jan 04, 2003
Posts: 2
Another weird question from me.
I'm developing a modular system and want to write a small thing for the different modules to be able to easily "upload" Objects, bound to keys, into the session. I've solved this by simply putting up a Hashtable into the HttpSession and creating a couple of "helper-methods" for the aforementioned modules to get/set their Objects.
The question: Would I have to do a session.setAttribute() every time the set-method updates the Hashtable, or is it enough to do that setAttribute() once when creating the Hashtable?
Do HttpSession attributes store references or entire objects?
Thanks for any help.
Chamooze
Asher Tarnopolski
Ranch Hand

Joined: Jul 28, 2001
Posts: 260
i guess that like almost everything in java
it's a references stored in session.


Asher Tarnopolski
SCJP,SCWCD
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
The question: Would I have to do a session.setAttribute() every time the set-method updates the Hashtable, or is it enough to do that setAttribute() once when creating the Hashtable?
Do HttpSession attributes store references or entire objects?

That depends - are you recovering the Hashtable from the session or creating a new one? If you are recovering the Hashtable from the session you don't have to add it again. If you are creating a new Hashtable every time, when you do a setAttribute the new will replace the old.
Of course sessions store references, every collection stores references. However, if the session is serialized out by the servlet engine then the object will be serialized with the session. Thats why you may get odd results if your custom object is not Serializable.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Do HttpSession attributes store references or entire objects?
 
Similar Threads
Session variable
Distributed Web application question
a statement about Session
large object graphs inside an HttpSession?
Purging attributes from HttpSession