Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will session.invalidate() remove the attribute set to the session?

Tags:

jsp

servlets

If I set the attribute value in the request and after that I call session.invalidate(), what will happen to attribute values? Will they be there still?

like image 686
tom Avatar asked Sep 20 '11 12:09

tom


People also ask

What happens when we invalidate a session?

session. invalidate(); All objects bound to the session are removed.

How do I remove a specific attribute from a session?

Remove a particular attribute − You can call the public void removeAttribute(String name) method to delete the value associated with the particular key. Delete the whole session − You can call the public void invalidate() method to discard an entire session.

Which method removes attributes specified by attr from the session?

The Element method removeAttribute() removes the attribute with the specified name from the element.

What does session invalidated mean?

Session invalidation means session destroying.So if session is destroyed,it indicates that server cant identify the client which has visited in previous.So now it creates a new session id for that client.


2 Answers

They will be still in memory, but they are not referenced by the HttpSession in question anymore. I.e. they are not accessible by HttpSession anymore.

Once the Garbage Collector runs and those objects do not have any other references by any other classes/instances, then they will ultimately be destroyed and free memory.

like image 145
BalusC Avatar answered Oct 04 '22 14:10

BalusC


request and sessions are two different things. attributes set in request will be available until you serve the request. Once done all values will be vanished.

Attributes in session will be there until session gets expired or you call invalidate explicitly. Either of these will kill the current session and create a new one on next request onwards.

like image 32
Nageswara Rao Avatar answered Oct 04 '22 13:10

Nageswara Rao