简体   繁体   中英

Stop jsp page from caching

Okay, so my nocache filter doesn't seem to work. I've read other stackoverflow questions but their answers doesn't seem to work too. I'm using firefox. Tried clearing cache, restarted tomcat. Filter is called too and header shows page is not cached. BUT when I click the back button page still loads..what to do?

public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain)
        throws IOException, ServletException {
    HttpServletResponse httpResponse = (HttpServletResponse) response;
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    // Set standard HTTP/1.1 no-cache headers.
    httpResponse.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate");
    // Set standard HTTP/1.0 no-cache header.
    httpResponse.setHeader("Pragma", "no-cache");
    httpResponse.setDateHeader("Expires", 0); //prevents caching at the proxy server
    String method = httpRequest.getMethod();
    String URI = httpRequest.getRequestURI();
    System.out.println(method + " request invoked on " + URI);
    chain.doFilter(httpRequest, httpResponse);
}

EDIT: I also did try putting < meta> tags, no good..

Try Below

 httpResponse.setDateHeader("Expires", -1); //Add this line

 httpResponse.setDateHeader("Expires", 0);//Remove this line

Find detail here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM