只需要两步:
1、定义一个Filter:
public class NoCacheFilter implements Filter{ @Override public void destroy(){ } @Override public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException{ HttpServletResponse response = (HttpServletResponse)resp; response.setDateHeader("Expires", -1); //设置页面失效时间 response.setHeader("Cache_Control", "no-cache"); //支持HTTP1.1 response.setHeader("Pragma", "no-cache"); //支持HTTP1.0 chain.doFilter(req, resp); } @Override public void init(FilterConfig arg0) throws ServletException { } }
<!-- 防止浏览器缓存页面或请求结果 --> <filter> <filter-name>NoCacheFilter</filter-name> <filter-class>com.xyt.cgqm.mvc.filter.NoCacheFilter</filter-class> </filter>
版权声明:本文为原创文章,转载请注明转自Clement-Xu的csdn博客。
原文地址:http://blog.csdn.net/clementad/article/details/46763669