jspsessionservletssession-variablessessiontracking

Trouble in session logout


I have read that there is the method logout() that we can use in servlets. So,I am doing something like this

HttpSession sr=request.getSession();
sr.logout();

But this gives me an error that it cannot find the symbol logout(); Plz help.I want the user to logout and go to home page(home.jsp).


Solution

  • There is no logout method exist in HttpSession

    //This code will redirect to  homepage.jsp
     RequestDispatcher rd = request.getRequestDispatcher("homepage.jsp");
      rd.forward(request, response);
    

    You can use session.invalidate(); to invalidate the session