• Post Reply Bookmark Topic Watch Topic
  • New Topic

How HTTP session manages its attribute  RSS feed

 
Thomas Vezhambassery
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

suppose I am putting same object in HTTP session as two attribute. If i am changing one object, whether it will be reflected other object?

For ex. consider I have object obj1

session.setAttribute("A",obj1);
session.setAttribute("B",obj1);

And some where if I am retrieving obj1 through "A" and changing its status whether it will be reflected in "B".

Regards,
Thomas
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Thomas V J",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Thomas V J:

suppose I am putting same object in HTTP session as two attribute. If i am changing one object, whether it will be reflected other object?


Yes, because there is no "other object". You are placing two references to the same object into the session, not the object itself.
 
ak pillai
author
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, if you are running in a clustered environment then you need to explictly call the setAttribute()for your changes to get synchronized.

Example:

If you have an ArrayList in the session representing shopping cart objects and if you just call getAttribute() to retrieve the ArrayList and then add or change something without calling the setAttribute(�����) then the container may not know that you have added or changed something in the ArrayList. So the session will not be replicated.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!