% response.setHeader("Cache-Control","no-cache");//HTTP1.1 response.setHeader("Pragma","no-cache");//HTTP1.0 response.setDateHeader("Expires",0);//preventscachingattheproxyserver % 一、清除页面缓存 在jsp页里 ? 1 2 3 4 %response.s
- <%
- 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
- %>
一、清除页面缓存
-
在jsp页里
? 1 2 3 4<%response.setHeader(
"Pragma"
,
"No-cache"
);
response.setHeader(
"Cache-Control"
,
"no-cache"
);
response.setDateHeader(
"Expires"
,
0
);
response.flushBuffer();%>
在html页里:
? 1 2 3 4<
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
? 1 2 3 4 5 6<%
Cookie killMyCookie =
new
Cookie(
"mycookie"
,
null
);
killMyCookie.setMaxAge(
0
);
killMyCookie.setPath(
"/"
);
response.addCookie(killMyCookie);
%>
三、清除session
清除session方法
? 1 2 3 4<%@ page language=
"java"
%>
<%
session.invalidate();
%>
在页面关闭时清除session,需要捕获windows.onclose事件,再调用清除session方法
补充:如何使用 JavaScript 代码清除缓存?
如果在服务器级不能生成随机数,您可以使用 JavaScript 代码在客户端(浏览器)级生成一个字符串。以下示例图解说明如何使用标准图像代码或 Iframe/JavaScript 代码执行缓存清除。
这些仅为示例。如果要使用该代码,请为特定 HTML 代码对示例作相应调整。您必须将实际代码粘贴到这些示例中的相应位置。
标准图像代码示例:
? 1 2 3 4 5 6 7 8 9 10 11<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://img.558idc.com/uploadfile/allimg/210625/1541103c2-0.jpg
+ 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 代码示例:
? 1 2 3 4 5 6 7 8 9 10 11 12<SCRIPT LANGUAGE=
"JavaScript"
>
<!== hide from non-JavaScript browsers
var
axel = Math.random() +
""
;
var
num = axel * 1000000000000000000;
document.writeln(
‘<IFRAME SRC="http://img.558idc.com/uploadfile/allimg/210625/15411021Y-1.jpg
+ 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://img.558idc.com/uploadfile/allimg/210625/1541101202-2.jpg
+ 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>