【问题标题】:Disabling browser caching in Tomcat 6在 Tomcat 6 中禁用浏览器缓存
【发布时间】:2023-03-18 01:58:01
【问题描述】:

我们希望 Web 服务器在包含敏感内容的所有响应中返回以下 http 标头:

Cache-control:no-store
Pragma:no-cache.

我们使用的是tomcat server 6.0版本。

请建议我们必须在哪里进行更改。

【问题讨论】:

标签: jsp tomcat browser-cache


【解决方案1】:

这样的 Servlet 过滤器应该会有所帮助:

public class ResourceCacheFilter implements Filter {
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletResponse res = (HttpServletResponse) response;
        res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
        res.setHeader("Pragma", "no-cache");
        chain.doFilter(request, response);
    }
}

【讨论】:

  • 当我添加这个并在 web.xml 中添加过滤器 url 映射时。但是 myClientapp/*CacheManagerFilter filter-name> *.jsp `这会导致问题。当我添加过滤器管理器时,所有页面都变为空白,如果我删除,那么它将加载页面。如何解决这个问题?
【解决方案2】:

根据您的安全约束,您可以将 tomcat 阀门设置为将 securePagesWithPragma 设置为 true(默认),这将根据您的要求设置标题。 更多详情请参考Tomcat6 Valve Documentation,也请参考Tomcat: Cache-Control

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-05
    • 2018-08-30
    • 1970-01-01
    • 1970-01-01
    • 2018-06-29
    • 2011-07-25
    相关资源
    最近更新 更多