File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Do HttpSession attributes store references or entire objects?

 
Tommy Sedin
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 260
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i guess that like almost everything in java
it's a references stored in session.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13047
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic