| 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: 12268
|
|
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
|
Java Resources at www.wbrogden.com
|
 |
 |
|
|
subject: Do HttpSession attributes store references or entire objects?
|
|
|