Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Tomcat 7中子域的缓存控制_Java_Caching_Tomcat7 - Fatal编程技术网

Java Tomcat 7中子域的缓存控制

Java Tomcat 7中子域的缓存控制,java,caching,tomcat7,Java,Caching,Tomcat7,我可以使用下面的过滤器处理核心域(www.domain.com)上的缓存 public class cacheControl implements Filter{ FilterConfig filterConfig; public cacheControl() { filterConfig = null; } @Override public void init(FilterConfig filterConfig) throws Se

我可以使用下面的过滤器处理核心域(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、图像之类的静态内容放在(static.domain.com)上,我想为来自该静态域的内容设置过期标题。我在谷歌上搜索过,但没有完美的解决方案。请帮助我为静态域设置到期头…

将筛选器添加到您的根
web.xml
中,并检查传入请求的URL。我在web.xml中添加了筛选器。您可以向
筛选器添加一些参数,这些参数作为标准java bean工作,以使其可定制。但是,如果您想硬编码它,您所需要做的就是检查URL及其值的分支。