This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Servlets and the fly likes Session Objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session Objects" Watch "Session Objects" New topic

Session Objects

Mrigasira Srinivas

Joined: Feb 28, 2001
Posts: 17
Hello All,
I am placing an object containing data retrieved in session for displaying it on multiple screens. When the user clicks on the save button, I need to update the session object (such that I can display the changed data if there is an error for the user), and also have the old object in order to make some comparisons. I have tried placing the same object in session with two different names, but that did not help. Can someone please let me know what I am doing wrong?
Asher Tarnopolski
Ranch Hand

Joined: Jul 28, 2001
Posts: 260
if you need to keep both of the objects in your session-set 2 different attributes with 2 different names.
if you have problems with your code - post it here.

Asher Tarnopolski
Andy Bowes
Ranch Hand

Joined: Jan 14, 2003
Posts: 171
It sounds like you are adding 2 entries into your session which actually both reference the SAME java object, i.e. the changes made to the object will be displayed regardless of which key you use to retreive it from the session.
You will need to create a COPY of the original object, apply the changes to the copy and then add this copy into the session.

Andy Bowes<br />SCJP, SCWCD<br />I like deadlines, I love the whoosing noise they make as they go flying past - Douglas Adams
Mrigasira Srinivas

Joined: Feb 28, 2001
Posts: 17
Thanks Andy... That is what I was doing - putting the same object in session with different names. Copy seems to work.
I agree. Here's the link:
subject: Session Objects
It's not a secret anymore!