-2

In my web java application, I succeed to logout from the principal page to the index page but when I clicked the back button of the browser I had the principal page in spite of I didn't enter my user name and my password.

  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

     request.getRequestDispatcher("index.html").include(request, response);  

        HttpSession session=request.getSession();  
        session.invalidate();  
           out.close();  
}
mass_develop
  • 43
  • 1
  • 7

2 Answers2

2

I clicked the back button of the browser I had the principal page in spite of I didn't enter my user name and my password

Browser back button does not makes request to the server. It is loaded from the cached page, so even if you have the session validation it won't work here.

You can possibly use client side script to resolve this issue. I had the same issue resolved by using this script, you need to have this on all pages which is requires valid session.

Edited:

<script>
  history.forward();
  if(window.attachEvent) {// extra step for IE
    window.attachEvent('onload', function() {});
  }
</script>
  • Does this kind of script introduce those annoying website behaviour, where you have to smash your back button to death, if you want to go beyond the site with that script? – Zhedar Apr 22 '15 at 12:28
  • @Zhedar, let me know once you have tried for yourself. –  Apr 22 '15 at 14:31
1

That is caused by your browser's caching for sure.

You can turn the caching off for your login page by setting some header information.

Quoted from this answer:

// Set standard HTTP/1.1 no-cache headers.
response.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate");

// Set standard HTTP/1.0 no-cache header.
response.setHeader("Pragma", "no-cache");

//Proxies
response.setDateHeader("Expires", 0);
Community
  • 1
  • 1
Zhedar
  • 3,480
  • 1
  • 21
  • 44