• 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

How to kill session

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about using removeAttribute() with session invalidate? Will it make any difference?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic