我用这种方法。首先创建一个实现Filter的类并重写doFilter()方法。doFilter()的代码是:
@Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {HttpServletResponse hsr = (HttpServletResponse) res;hsr.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.hsr.setHeader("Pragma", "no-cache"); // HTTP 1.0.hsr.setDateHeader("Expires", 0); // Proxies.chain.doFilter(req, res); }
之后在web.xml中使用过滤器。这个过滤器就是这个。
<filter> <filter-name>noCacheFilter</filter-name> <filter-class>com.example.NoCacheFilter</filter-class> </filter> <filter-mapping> <filter-name>noCacheFilter</filter-name> <url-pattern>/secured/*.jsp</url-pattern>// urls that not cached </filter-mapping>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)