JavaWeb-禁用浏览器缓存

一.禁用浏览器缓存可以通过设置响应头的方式,有如下3个响应头可禁用浏览器缓存问题

  1.Cache-control

  2.pragma

  3.expires

 

二。代码示例

package cn.xxx.Servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class FServlet extends HttpServlet {
    
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setHeader("Cache-control", "no-cache");
        response.setHeader("pragma", "no-cache");
        response.setDateHeader("expires", -1);
    }
}

 

posted @ 2020-02-11 11:33  爱编程DE文兄  阅读(738)  评论(0编辑  收藏  举报