package com.filter;
import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;
public class ResponseHeaderFilter implements Filter {
FilterConfig fc;
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {
HttpServletResponse response = (HttpServletResponse) res;
// set the provided HTTP response parameters
Enumeration e = fc.getInitParameterNames();
while (e.hasMoreElements()) {
String headerName = (String) e.nextElement();
response.addHeader(headerName, fc.getInitParameter(headerName));
}
// pass the request/response on
chain.doFilter(req, response);
}
public void init(FilterConfig filterConfig) {
this.fc = filterConfig;
}
public void destroy() {
this.fc = null;
}
}
在这里以.do
结尾的请求均为动态请求
在web.xml中添加
<filter>
<filter-name>NoCache</filter-name>
<filter-class>com.filter.ResponseHeaderFilter</filter-class>
<init-param>
<param-name>Cache-Control</param-name>
<param-value>no-cache</param-value>
</init-param>
<init-param>
<param-name>Pragma</param-name>
<param-value>No-cache</param-value>
</init-param>
<init-param>
<param-name>Expires</param-name>
<param-value>0</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>NoCache</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
```
http://blog.csdn.net/liujin4049/article/details/3010370