强制JSP页面刷新,防止被服务器缓存(可用于静态include强制刷新)

对于jsp页面,为了防止页面被服务器缓存、始终返回同样的结果。

通常的做法是在客户端的url后面加上一个变化的参数,比如加一个当前时间。

我现在使用的方法是在jsp头部添加以下代码:

<%
    request.setAttribute("decorator", "none");
    response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
    response.setHeader("Pragma","no-cache"); //HTTP 1.0
    response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
%>

这样如果有多个调用此页面的链接就不需要一个一个全部添加参数了。

原文地址:https://www.cnblogs.com/sprinng/p/4309551.html