2

In the application am working when the user logs out and press the browser back button it takes the particular user to the previous page(logged in as the previous user).

I tried the following code to clear the cache when the user logs out in the index(login) page

<%
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-store");
response.setHeader("Expires", "0");
response.setDateHeader("Expires", -1);
%>

The above code works fine in IE and firefox but not in google chrome ,

can any one helps me in solving this issue with google chrome .

Thanks in advance .

seeker
  • 6,841
  • 24
  • 64
  • 100
Jey Ravi
  • 49
  • 1
  • 1
  • 5

2 Answers2

1

You need to change the following:

response.setHeader("Cache-Control", "no-store");

to:

response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");

Read this post for further description.

Community
  • 1
  • 1
Kazekage Gaara
  • 14,972
  • 14
  • 61
  • 108
1

There are 2 mistakes here:

  1. The Cache-Control header is incomplete. The complete set of proper headers is:

    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
    response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
    response.setDateHeader("Expires", 0); // Proxies.
    

    Make sure that you've cleared your browser cache before testing.

  2. Those headers have to be set on the response of the restricted pages, not only on the login page. Easiest way is to create a servlet filter which is mapped on the very same URL pattern as the restricted pages and set those headers in doFilter() method.

    public class NoCacheFilter implements Filter {
    
        @Override
        public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
            HttpServletResponse response = (HttpServletResponse) res;
            response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
            response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
            response.setDateHeader("Expires", 0); // Proxies.
            chain.doFilter(req, res);
        }
    
        // ...
    }
    

    If you're already using a custom filter on the URL pattern of the restricted pages which needs to check the presence of the logged-in user and handle the redirect to the login page, then you can also do the job in the very same filter instead.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555