How to clear browser cache using java

user1407310 picture user1407310 · Jun 7, 2012 · Viewed 13.5k times · Source

I have a problem in sessions. When ever I logout the session is ended but then when the browsers back button is pressed I am getting the previous page. I am using jsp servlet technology and my code for logout is given below

                    request.getSession().invalidate();
        response.setHeader("Cache-Control","no-cache"); 
        response.setDateHeader("Expires", 0);
        response.setHeader("Pragma","no-cache"); 
        response.sendRedirect("home.jsp");

can anybody tell me where is the problem and what will be the solution for this problem?

Answer

tom picture tom · Jun 7, 2012

Do you set the cache headers only on the logout page? If so, you need to put those on each page since the page you were coming from does not have them and will be cached.