Tomcat 7中子域的缓存控制

时间:2013-05-14 11:32:07

标签: java caching tomcat7

我可以使用以下过滤器

处理核心域上的缓存(www.domain.com)
public class cacheControl implements Filter{

    FilterConfig filterConfig;

    public cacheControl() {
        filterConfig = null;
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        this.filterConfig = filterConfig;
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
         String sCache = filterConfig.getInitParameter("cache");
        if (sCache != null) {
            Date _currentDate = new Date();
            ((HttpServletResponse) response).setHeader("Cache-Control", sCache);
            ((HttpServletResponse) response).setHeader("Expires", new Date(_currentDate.getYear(), _currentDate.getMonth(), _currentDate.getDate() + 10).toString());
            ((HttpServletResponse) response).setHeader("X-Content-Type-Options", "nosniff");
            ((HttpServletResponse) response).setHeader("X-XSS-Protection", "1; mode=block");
            ((HttpServletResponse) response).setHeader("X-Frame-Options", "SAMEORIGIN");
            ((HttpServletResponse) response).setHeader("X-UA-Compatible", "IE=edge, chrome=1");
        }
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {
        filterConfig = null;
    }
}

但我把静态内容如javascripts,css,images放在(static.domain.com)上,我想为来自该静态域的内容设置expiry标头。我用谷歌搜索,但没有完美的解决方案。请帮我设置静态域的到期标题....

0 个答案:

没有答案