好吧,所以我的nocache过滤器似乎不起作用。我读过其他stackerflow问题,但它们的答案似乎也不起作用。我在用萤火虫。尝试清除缓存,重新启动tomcat。过滤器也被调用,并且标题显示页面未被缓存。但当我点击后退按钮时,页面仍然加载。。该怎么办?
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);
}
编辑:我也试着把<meta>标签,不好。。
尝试低于
httpResponse.setDateHeader("Expires", -1); //Add this line
httpResponse.setDateHeader("Expires", 0);//Remove this line
在此处查找详细信息