0

我可以使用以下过滤器处理核心域(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;
    }
}

但是我在(static.domain.com)上放置了像javascripts、css、图像这样的静态内容,并且我想为来自该静态域的内容设置过期标头。我用谷歌搜索,但没有完美的解决方案。请帮我设置静态域的到期标头....

4

0 回答 0