Invalidating a session in java

I have idea like by using Http Session Listener we can do.

invalidating a session in java-39invalidating a session in java-15

My jsp page gets called on click of a link in my application.

What I need to do is My jsp page should check if the current session is still valid & if it is then invalidate the session & redirect to another page outside the application. Please let me know how to check, if the sesion is valid & invaidate it if it is valid. As per my knowledge in a jsp page session object can never be null, because if you look at the _jsp Service method of servlet(jsp compiled servlet) the following line of code gets executed session = page Session(); means your session object is not null.

Returns null if the request does not have a session associated with it.

Binds the specified object into the session with the given name.

Calling the method with no arguments creates a session that is associated with the request if one does not already exist.

Additionally, calling the method with a Boolean argument creates a session only if the argument is Returns a Boolean value indicating that the session is new.

You can also bind objects to the session, which store them for use by other components.

This section includes the following topics: returns the valid session object associated with the request, identified in the session cookie that is encapsulated in the request object.

Once the session is established, examine and set its properties using the provided methods.

If desired, set the session to time out after being inactive for a defined time period, or invalidate it manually.

When even you want to invalidate the sessions get the list of values in the map from Servlet Context, iterate through it and invalidate one by one, clear the list. This could present a problem when you iterate through the map and call invalidate on each session.

Tags: , ,