JSP clear Page Caching common methods summary _jsp programming

Source: Internet
Author: User
Tags html page ord

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.