JSP technology sharing: four methods to disable caching

Source: Internet
Author: User

[It168 technology] The following are four methods to prohibit Caching:

1. The client cache should include the following content in the head:
<! -- <Br/> code highlighting produced by actipro codehighlighter (freeware) <br/> http://www.CodeHighlighter.com/<br/> --> <meta HTTP-EQUIV = "Pragma" content = "no-Cache">
<Meta HTTP-EQUIV = "cache-control" content = "no-cache, must-revalidate">
<Meta HTTP-EQUIV = "expires" content = "wed, 26 Feb 1997 08:21:57 GMT">

Or
<! -- <Br/> code highlighting produced by actipro codehighlighter (freeware) <br/> http://www.CodeHighlighter.com/<br/> --> <meta http-equiv = "Pragma" content = "no-Cache">
<Meta http-equiv = "cache-control" content = "no-Cache">
<Meta http-equiv = "expires" content = "0">

2. Disable caching on the dynamic web page of the server. Add a script similar to the following:
<! -- <Br/> code highlighting produced by actipro codehighlighter (freeware) <br/> http://www.CodeHighlighter.com/<br/> --> response. setheader ("Pragma", "No-Cache ");
Response. setheader ("cache-control", "No-Cache ");
Response. setdateheader ("expires", 0 );

3. Set a limited time cache:
<! -- <Br/> code highlighting produced by actipro codehighlighter (freeware) <br/> http://www.CodeHighlighter.com/<br/> --> int minutes = 10;
Date d = new date ();
String moddate = D. togmtstring ();
String expdate = NULL;
Expdate = (new date (D. gettime () + minutes * 60000). togmtstring ();
Response. setheader ("last-modified", moddate );
Response. setheader ("expires", expdate );
Response. setheader ("cache-control", "public"); /// HTTP/1.1
Response. setheader ("Pragma", "Pragma"); /// HTTP/1.0

Suggestion: It is recommended that JSP cache be implemented on the filter, so that the pages to be buffered are concentrated in the same directory. You only need to modify web. XML to complete the buffer settings for each change, which is more convenient.

4. If none of the above methods works, add a tail after your normal URL.

In JS, select:
<! -- <Br/> code highlighting produced by actipro codehighlighter (freeware) <br/> http://www.CodeHighlighter.com/<br/> --> var timestamp = (new date ()). valueof ();
URL + "& timestamp =" + timestamp;

In the Java code, select:
<! -- <Br/> code highlighting produced by actipro codehighlighter (freeware) <br/> http://www.CodeHighlighter.com/<br/> --> long timestamp = new date (). gettime ();
URL + "& timestamp =" + timestamp;

In this case, your url is always changing, and the browser will have to update it honestly, and there is no buffer available.

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.