Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to kill session  RSS feed

 
anmolkumar kumar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am implementing shopping cart demo. & storing the items using the hash table. I am using an integer variable(iItems) to count the number of items in the cart.
If i am pressing the logout button in .jsp , i am making the session variables invalidate but iItems(Count integer variables) do not make becomes null in my servlet.
I declared iItems=0 , above my service method in servlet. I can't declare iItems inside the service method in servlet because my add & delete functionality will not work.
So, when new user log in he is getting the count(iItems) of the previous session not starting with iItems=0.
Can anyone provide me the solution how to make my iItems(Count integer variables) in servlet as zero.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a reference to an object that is stored as an attribute on a session, invalidating the session will have no effect whatsoever on the object.

If there are no references to the object other than the session, invalidating the session will make the object subject to garbage collection.

Under no circumstances will invalidating a session cause any objects to "reset" or any other such activity.
 
michael yue
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about using removeAttribute() with session invalidate? Will it make any difference?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, removeAttribute will just remove the map entry to the object. The object itself will be unaffected.

If you need to 'reset' the object you will either need to do it in the code that invalidates the session, or to implement a listener that will be called when the attribute is unbound.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!