本文实例总结了jsp清除页面缓存常用方法。分享给大家供大家参考,具体如下:
一、清除页面缓存
在jsp页里
<%response.setheader("pragma","no-cache");
response.setheader("cache-control","no-cache");
response.setdateheader("expires", 0);
response.flushbuffer();%>
在html页里:
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
二、清除cookie
<%
cookie killmycookie = new cookie("mycookie", null);
killmycookie.setmaxage(0);
killmycookie.setpath("/");
response.addcookie(killmycookie);
%>
三、清除session
清除session方法
<%@ page language="java" %>
<%
session.invalidate();
%>
在页面关闭时清除session,需要捕获windows.onclose事件,再调用清除session方法
补充:如何使用 javascript 代码清除缓存?
如果在服务器级不能生成随机数,您可以使用 javascript 代码在客户端(浏览器)级生成一个字符串。以下示例图解说明如何使用标准图像代码或 iframe/javascript 代码执行缓存清除。
这些仅为示例。如果要使用该代码,请为特定 html 代码对示例作相应调整。您必须将实际代码粘贴到这些示例中的相应位置。
标准图像代码示例:
<script language="javascript">
<!== hide from non-javascript browsers
var axel = math.random() + "";
var num = axel * 1000000000000000000;
document.writeln('<a href="http://ad.doubleclick.net/jump/n409.somesite/b470;sz=468x60;ord='+ num +'?"><img src="http://ad.doubleclick.net/ad/n409.somesite/b470;sz=468x60;ord='+ num +'?" border=0 width=468 height=60 alt="click here!"> click here!</a>');
// end hide from browsers ==>
</script>
<noscript>
<a href="http://ad.doubleclick.net/jump/n409.somesite/b470;sz=468x60;ord=[timestamp]?">
<img src="http://ad.doubleclick.net/ad/n409.somesite/b470;sz=468x60;ord=[timestamp]?" border=0 width=468 height=60 alt="click here!"> click here!</a>
</noscript>
iframe/javascript 代码示例:
<script language="javascript">
<!== hide from non-javascript browsers
var axel = math.random() + "";
var num = axel * 1000000000000000000;
document.writeln('<iframe src="http://ad.doubleclick.net/adi/n409.somesite/b470;sz=468x60;ord='+ num +'?" width=470 height=62 marginwidth=0 marginheight=0hspace=0 vspace=0 frameborder=0 scrolling=no bordercolor="#000000">');
document.writeln('<scr'+'ipt language="javascript1.1" src="http://ad.doubleclick.net/adj/n409.somesite/b470;abr=!ie;sz=468x60;ord='+ num +'?"></scr'+'ipt></iframe>');
// end hide from browsers ==>
</script>
<noscript>
<a href="http://ad.doubleclick.net/jump/n409.somesite/b470;abr=!ie4;abr=!ie5;sz=468x60;ord=?">
<img src="http://ad.doubleclick.net/ad/n409.somesite/b470;abr=!ie4;abr=!ie5;sz=468x60;ord=?" border=0 width=468 height=60 alt="click here!"> click here!</a>
<noscript>
希望本文所述对大家jsp程序设计有所帮助。
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!