Summary of common methods for clearing page cache in JSP and summary of page cache in jsp

Source: Internet
Author: User

Summary of common methods for clearing page cache in JSP and summary of page cache in jsp

This example summarizes common methods for clearing page cache in JSP. We will share this with you for your reference. The details are as follows:

1. 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();%>

On 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">

Ii. Clear cookies

<%   Cookie killMyCookie = new Cookie("mycookie", null);   killMyCookie.setMaxAge(0);   killMyCookie.setPath("/");   response.addCookie(killMyCookie); %>

3. Clear session

Session clearing method

<%@ page language="java" %> <% session.invalidate(); %>

Clear the session when the page is closed. Capture the windows. onclose event and call the clear session method.

Supplement: How can I clear the cache using JavaScript code?

If a random number cannot be generated at the server level, you can use JavaScript code to generate a string at the client (browser) level. The following illustration shows how to use standard image code or Iframe/JavaScript code to perform cache cleanup.

These are examples only. If you want to use this code, adjust the sample accordingly for the specific HTML code. You must paste the actual code to the corresponding position in these examples.

Sample Code for a standard image:

<SCRIPT LANGUAGE="JavaScript"><!== hide from non-JavaScript browsersvar 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 browsersvar 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=?"> Click Here!</A><noscript>

I hope this article will help you with JSP program design.

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.