title: Invalidate session in Logout Servlet
body: <pre><code>HttpSession session  = request.getSession();
  try
  {      
      session.removeAttribute("logonSessData");
      session.invalidate();                               
      String pageToForward = request.getContextPath();
      response.sendRedirect(pageToForward);           
  }
  catch (Exception sqle)
  {
      System.out.println("error UserValidateServlet message : " + sqle.getMessage());
      System.out.println("error UserValidateServlet exception : " + sqle);
  }
  </code></pre>
  
  <p>in Logout servlet I wrote above code in <code>doPost</code> and <code>doGet</code> method. After logout it shows login screen and then if I press back button it shows previous screen before logout and then if I click on any page it shows "HTTP Status 500" and now if I press <kbd>F5</kbd> then it's heating login Servlet and getting the full access of user. </p>
  
  <p>How to stop this problem show that after Logout using back button and <kbd>F5</kbd> user can not use any page? </p>