笔记如下
<filter>
<filter-name>NoCacheFilter</filter-name>
<filter-class>com.chen.demo2.NoCacheFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>NoCacheFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
//设置全站不缓存
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
// TODO Auto-generated method stub
HttpServletRequest request2 = (HttpServletRequest)request;
HttpServletResponse response2 = (HttpServletResponse) response;
response2.setHeader("cache-control", "no-cache");
response2.setHeader("pragma", "no-cache");
response2.setDateHeader("expires", 0);
chain.doFilter(request2, response2);
}
网友评论