加入收藏 | 设为首页 | 会员中心 | 我要投稿 聊城站长网 (https://www.0635zz.com/)- 智能语音交互、行业智能、AI应用、云计算、5G!
当前位置: 首页 > 教程 > 正文

让JSP停止读缓存时按 IE后退按钮

发布时间:2023-05-31 13:35:08 所属栏目:教程 来源:
导读:在asp里我曾告诉过朋友如何让asp程序不从缓存里读取数据,同样在jsp里也能实现,请看下面:

方法一:

1,使用java提供的方法,在jsp或者servlet中都可以

<%

response.setheader("pragma","no-cache");
在asp里我曾告诉过朋友如何让asp程序不从缓存里读取数据,同样在jsp里也能实现,请看下面:
 
方法一:
 
1,使用java提供的方法,在jsp或者servlet中都可以
 
<%
 
response.setheader("pragma","no-cache");
 
response.setheader("cache-control","no-cache");
 
response.setdateheader("expires",0);
 
%>
 
2,使用html标记,如下面:
 
<head>
 
<metahttp-equiv="pragma"content="no-cache">
 
<metahttp-equiv="cache-control"content="no-cache">
 
<metahttp-equiv="expires"content="0">
 
</head>
 
附加说明:
 
http头信息“expires”和“cache-control”为应用程序服务器提供了一个控制浏览器和代理服务器上缓存的机制。http头信息expires告诉代理服务器它的缓存页面何时将过期。http1.1规范中新定义的头信息cache-control可以通知浏览器不缓存任何页面。当点击后退按钮时,浏览器重新访问服务器已获取页面。如下是使用cache-control的基本方法:
 
  1) no-cache:强制缓存从服务器上获取新的页面
 
  2) no-store: 在任何环境下缓存不保存任何页面
 
  http1.0规范中的pragma:no-cache等同于http1.1规范中的cache-control:no-cache,同样可以包含在头信息中。
 
  通过使用http头信息的cache控制,第二个示例应用logoutsamplejsp2解决了logoutsamplejsp1的问题。logoutsamplejsp2与logoutsamplejsp1不同表现在如下代码段中,这一代码段加入进所有受保护的页面中:
 
//...
 
response.setheader("cache-control","no-cache"); //forces caches to obtain a new copy of the page from the origin server
 
response.setheader("cache-control","no-store"); //directs caches not to store the page under any circumstance
 
response.setdateheader("expires", 0); //causes the proxy cache to see the page as "stale"
 
response.setheader("pragma","no-cache"); //http 1.0 backward compatibility
 
string username = (string) session.getattribute("user");
 
if (null == username) {
 
 request.setattribute("error", "session has ended. please login.");
 
 requestdispatcher rd = request.getrequestdispatcher("login.jsp");
 
 rd.forward(request, response);
 
}
 
//...
 
方法二:
 
   在ie中也可通过设置实现:把/工具/internet选项/常规/设置/的检察所存页面的较新版本,设为每次访问该页时都检查.
 
 
 

(编辑:聊城站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!