Forums Register Login

How to kill session

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
How about using removeAttribute() with session invalidate? Will it make any difference?
+Pie Number of slices to send: Send
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.
A "dutch baby" is not a baby. But this tiny ad is baby sized:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1520 times.
Similar Threads
Session Problem
HttpSession
invisible intermediary servlet
Why doesn't exercise 8-1 from Murach's Java Servlets work for me on IE7?
Session info getting lost between servlets.
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 07:18:33.