• Post Reply Bookmark Topic Watch Topic
  • New Topic

session creation

 
Vinoth Thirunavukarasu
Ranch Hand
Posts: 164
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm creating session as session.setAttribute("arg",obj);.
Suppose I add the bellow code after create session.
session.setAttribute("arg",newObj);
Now which object will be returned when I use "session.getAttribute("arg");" either (obj) or (newObj)
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what do you find when you test this ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vinoth Thirunavukarasu wrote:Hi,
I'm creating session as session.setAttribute("arg",obj);.
Correction: that creates a scoped variable named arg in the session -- it does not create a session.

Seems easy enough to try out. As seetharaman asked, what happened when you tried it?
 
Vinoth Thirunavukarasu
Ranch Hand
Posts: 164
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I try this I got the newest object not the old one. But I don't know the old session object is destroyed or not.
 
Vijitha Kumara
Bartender
Posts: 3952
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vinoth Thirunavukarasu wrote:When I try this I got the newest object not the old one. But I don't know the old session object is destroyed or not.


Well, what actually you are trying to do? Do you need the old session object or a new one always? For that we need to look at how you create the object.
 
Vinoth Thirunavukarasu
Ranch Hand
Posts: 164
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply,

I want the new session object. My question is what will happened to old session object whether it will deleted from session or not.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vinoth Thirunavukarasu wrote:When I try this I got the newest object not the old one. But I don't know the old session object is destroyed or not.

Again, please use correct terminology. An object you place in session scope is called a scoped variable.

When you add the new scoped variable, the reference to the old one is removed. That object is then subject to garbage collection according to the rules of Java.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!