I opened the session in my servlet when the user performed a successful login:
HttpSession session = request.getSession(true);
session.setAttribute("name", name);
then I wrote in the logout.jsp to terminate the session:
<%session.invalidate();%>
To check if a session is valid I am doing this:
HttpSession session = request.getSession();
String name = (String) session.getAttribute("name");
But it is not working, I am getting the session valid even after the session.invalidate. Does anyone understand where am I doing wrong?
To Validate the Session
To invalidate it you need to do
But you need to keep one thing in mind that the object may became invalid but this doesnot mean that it will cleaned immediately, even after invalidating it after all its attributes gone it is possible that sesssion object will get reused, I got the same user ID and creation time.
you should call session.getSession(false) - which returns null if there is no current session.
according to docs
So the correct way of session value check would -
and once you invalidate the session -