session.invalidate() is sometimes not working and not destroying the session object. What should I do?

14 Views Asked by At
Public class Logout extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        
        HttpSession session = req.getSession();
        session.invalidate();

        RequestDispatcher rd = req.getRequestDispatcher("/index.html");
        rd.forward(req, resp);
        
    }
}

I am doing this in eclipse on Apache Tomcat server. When I restart the server sometimes the session object deletes but majority times it does not. In new browser I can still fetch the details after session.invalidate() is called.

I tried many other things like -

  • a return statement after RequestDispatcher.
  • and i even tried the below code as well -
 HttpSession session = request.getSession(false);  
 if (session != null) 
  session.setMaxInactiveInterval(1);

Nothing worked for me ;)

0

There are 0 best solutions below