• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

updating object in session

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have kept an object in session.
During the next call to the servlet i retrieve the object from session, update it.. but am not setting the object back in session.
But to my surprise when i retrieve the object in JSP i receive the updated object.
But the same doesn't work if i clear the files from Tools/Internet options
I think this has to do with some object references..
Plz clarify.
Thanks in Advance,
Nijeesh.
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
U don't need to call setAttribute() to set the updated object into session. When u get the object from session using getAttribute u are getting the refernce to the object so any change made to the object using the reference will be reflected to the object present in session since both of them refer to the same object...

Origina
lly posted by Nijeesh BH:
Hi,
I have kept an object in session.
During the next call to the servlet i retrieve the object from session, update it.. but am not setting the object back in session.
But to my surprise when i retrieve the object in JSP i receive the updated object.
But the same doesn't work if i clear the files from Tools/Internet options
I think this has to do with some object references..
Plz clarify.
Thanks in Advance,
Nijeesh.

 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pradeep --
I don't think that's quite right. Check out this simple series of JSPs -- you'll see that with both variables I change their value, but only ONE I update the session -- this is the only one who's new value is persisted in session to the next page:
index.jsp:

updateSession.jsp:

displaySession.jsp:
 
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nijeesh, presumably Tools/Internet Options & clearing files is clearing Internet Explorer's cache? I see no reason why doing that should affect what happens to the values in your session.
So what Jessica's code is doing is getting complete copies and not references.
Nijeesh, is your situation complicated or can you reduce it to a simple demo and post it?
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I completely agree with what Adam says - What Jessica's code is doing is getting complete copies and not references. this is because ur using Strings and Strings are immutable objects..!
U cannot change the value!
When u say
blah = "5678";
now blah is pointing to entriely new object.. but the session object points to "1234".
A better example will be to use vectors and then u will notice the difference..In this case u don't need to explicitly call SetAttribute ..just call getAttribute and make some changes to the obtained reference and u find for sure that changes will be reflected in session object !

Originally posted by Adam Hardy:
Nijeesh, presumably Tools/Internet Options & clearing files is clearing Internet Explorer's cache? I see no reason why doing that should affect what happens to the values in your session.
So what Jessica's code is doing is getting complete copies and not references.
Nijeesh, is your situation complicated or can you reduce it to a simple demo and post it?


\
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic