public class NocacheFilter implements Filter { public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse httpResponse = (HttpServletResponse)response; httpResponse.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); httpResponse.setHeader("Pragma", "no-cache"); httpResponse.setDateHeader("Expires", 0); chain.doFilter(request, response); } public void destroy() {} public void init(FilterConfig fConfig) throws ServletException {} }
这个我就是备注一下,就不发布了,需要在web.xml中注册一下或者使用Servlet3.0的版本@WebFilter