web.xml配置: 禁止游览器对动态内容做缓存

package com.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

public class ResponseHeaderFilter implements Filter {
    FilterConfig fc;

    public void doFilter(ServletRequest req, ServletResponse res,
                         FilterChain chain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse) res;
        // set the provided HTTP response parameters
        Enumeration e = fc.getInitParameterNames();
        while (e.hasMoreElements()) {
            String headerName = (String) e.nextElement();
            response.addHeader(headerName, fc.getInitParameter(headerName));
        }
        // pass the request/response on
        chain.doFilter(req, response);
    }

    public void init(FilterConfig filterConfig) {
        this.fc = filterConfig;
    }

    public void destroy() {
        this.fc = null;
    }

}

在这里以.do结尾的请求均为动态请求
在web.xml中添加

    <filter>
        <filter-name>NoCache</filter-name>
        <filter-class>com.filter.ResponseHeaderFilter</filter-class>
        <init-param>
            <param-name>Cache-Control</param-name>
            <param-value>no-cache</param-value>
        </init-param>
        <init-param>
            <param-name>Pragma</param-name>
            <param-value>No-cache</param-value>
        </init-param>
        <init-param>
            <param-name>Expires</param-name>
            <param-value>0</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>NoCache</filter-name>
        <url-pattern>*.do</url-pattern>
    </filter-mapping>
 ```
http://blog.csdn.net/liujin4049/article/details/3010370
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,987评论 19 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,486评论 25 708
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,970评论 6 342
  • 有段时间没有回家看妈妈了,再多的理由面对妈妈精心准备的一桌菜时,都显得那么苍白无力。 今天,带儿子回到妈妈的小院。...
    微风徐徐xp阅读 445评论 0 1
  • 我们总是在探索生活,可是,生活很多的时候会给予我们很多选择,而我们在选择过后,有时候会面对很多的错过,并且,错过了...
    钟离凌羽阅读 430评论 0 1