Search code examples
javaservletshttpsession

My session not became Null after invalidating the session


Hi Can anyone plz let me know what would be the problem in the following code.In this below code I have invalidated my session after creating the new session by using the http session.getsession(true) and setting the attribute also.Once I click the logout i am invalidating the session but that is not became null.

Here I am not getting null System.out.println("sess"+sess)

HttpSession sess = request.getSession(false);
sess.removeAttribute("name");
sess.invalidate(); 
System.out.println("sess"+sess);

Solution

  • As API said,

    Invalidates this session then unbinds any objects bound to it.

    It doesn't need to be null, it just unbinds the objects. You can check whether your previously set attributes are still there in the session.