The example of this article summarizes the common methods of JSP clearing page caching. Share to everyone for your reference, specific as follows:
First, clear the page cache
In the JSP page
<%response.setheader ("Pragma", "No-cache");
Response.setheader ("Cache-control", "No-cache");
Response.setdateheader ("Expires", 0);
Response.flushbuffer ();%>
In the HTML page:
<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 ">
Second, the elimination of cookies
<%
Cookie Killmycookie = new Cookie ("MyCookie", null);
Killmycookie.setmaxage (0);
Killmycookie.setpath ("/");
Response.addcookie (Killmycookie);
%>
Third, clear session
Clear Session Method
<%@ page language= "java"%>
<%
session.invalidate ();
%>
To clear the session when the page closes, you need to capture the Windows.onclose event, and then call the Purge session method
Supplemental: How do I clear the cache using JavaScript code?
If you cannot generate random numbers at the server level, you can use JavaScript code to generate a string at the client (browser) level. The following example illustrates how to perform cache cleanup using standard image code or iframe/javascript code.
These are examples only. If you want to use this code, make adjustments to the example for specific HTML code. You must paste the actual code into the appropriate location in these examples.
Standard Image code example:
<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 + '? ') > Click here!</a> ');
End hide from browsers ==>
</SCRIPT>
<NOSCRIPT>
<a href= "http://ad.doubleclick.net/ Jump/n409.somesite/b470;sz=468x60;ord=[timestamp]? " >
Click here!</a>
</NOSCRIPT>
Iframe/javascript code Example:
<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 "#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=? " > Click here!</a> <noscript>
I hope this article will help you with JSP programming.