Filter指定浏览器来缓存或不缓存服务器数据
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; public class ResponseHeaderFilter implements Filter { FilterConfig fc; public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException,ServletException { HttpServletResponse response = (HttpServletResponse) res; for (Enumeration e=fc.getInitParameterNames(); e.hasMoreElements();) { String headerName = (String)e.nextElement(); response.addHeader(headerName, fc.getInitParameter(headerName)); } chain.doFilter(req, response); } public void init(FilterConfig filterConfig) { this.fc = filterConfig; } public void destroy() { this.fc = null; } }
缓存
<filter> <filter-name>ResponseHeaderFilter</filter-name> <filter-class>com.jspbook.ResponseHeaderFilter</filter-class> <init-param> <param-name>Cache-Control</param-name> <param-value>max-age=3600</param-value> </init-param> </filter> <filter-mapping> <filter-name>ResponseHeaderFilter</filter-name> <url-pattern>/logo.png</url-pattern> </filter-mapping>
不缓存
<filter> <filter-name>ResponseHeaderFilter</filter-name> <filter-class>com.jspbook.ResponseHeaderFilter</filter-class> <init-param> <param-name>Cache-Control</param-name> <param-value>private,no-cache,no-store</param-value> </init-param> </filter>
相关推荐
学习web前端 2020-11-09
天空一样的蔚蓝 2020-10-23
curiousL 2020-08-03
sochrome 2020-07-29
SoarFly00 2020-06-28
LeoHan 2020-06-02
GimmeS 2020-05-15
逸璞丷昊 2020-03-08
DAV数据库 2020-05-07
Vampor 2020-05-01
ROES 2020-04-22
lifeforbug 2020-03-18
zhangwentaohh 2020-03-04
Freshairx 2020-11-10
liuyuchen 2020-10-27
chenhaimeimeng 2020-08-15
东哥笔记 2020-08-14
幸运小侯子 2020-08-14
vanturman 2020-08-01
shawls 2020-07-29
buaichidoufu 2020-07-28
guoyun0 2020-07-19
LinuxJob 2020-06-26
韩学敏 2020-06-17