Page caching and not caching settings and the role of meta in HTML pages _java

Source: Internet
Author: User
Tags microsoft frontpage

HTML HTTP protocol header information controls the page in several places cached information, including browser side, intermediate cache server (such as: squid, etc.), the Web server side. This article discusses the caching situation in the intermediate cache server for HTML pages with cached control information in header information (Jsp/servlet generated as well as HTML pages).

Information about caching in the HTTP protocol header keywords include cache-control (HTTP1.1), Pragma (HTTP1.0), Last-modified,expires, and so on.

HTTP1.0 control page caching through Pragma , you can set: Pragma or No-cache. There are a lot of articles on the web that show how to control the browser or intermediate cache server to cache the page, usually set a value of No-cache, but this value is not so insured, usually plus expires for 0来 to achieve the goal. But if we deliberately need the browser or cache server to cache our page This value is set to Pragma.

HTTP1.1 to enable Cache-control to control the caching of the page, here are some common parameters:

No-cache, browsers and caching servers should not cache page information;

public, browsers and caching servers can cache page information;

No-store, requests and response information should not be stored in the other's disk system;

must-revalidate, for each request from the client, the proxy server must want the server to verify that the cache is obsolete;

Last-modified only the last generation time of the page, GMT format;

Expires time limit, GMT format, refers to the browser or cache server after that point must be from the real server to obtain new page information;

The above two values in the JSP set the value of the GMT format of the character type, cannot take effect, set long to take effect;

Here is a test example:

Package com.servlet;
Import java.io.IOException;
Import Java.io.PrintWriter;
Import javax.servlet.ServletException;
Import Javax.servlet.http.HttpServlet;
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse;  public class Servleta extends HttpServlet {@Override the public void service (HttpServletRequest request, HttpServletResponse Response) throws Servletexception, IOException {response.setcontenttype ("text/html");//servlet page default is not cached//
This page allows caching in the browser-side or cached server, with a time limit of seconds. 
Re-entering the page within seconds will not enter the java.util.Date Date = new Java.util.Date () of the servlet; Response.setdateheader ("Last-modified", Date.gettime ()); Last-modified: The last generation time of the page Response.setdateheader ("Expires", Date.gettime () +); Expires: Obsolete term value response.setheader ("Cache-control", "public"); Cache-control to control the caching of pages, public: browsers and caching servers can cache page information; Response.setheader ("Pragma", "Pragma");
Pragma: Sets whether the page is cached, Pragma is cached, No-cache does not cache//does not allow the browser-side or cache server to cache the current page information. 
/*response.setheader ("Pragma", "No-cache"); Response.setdatehEader ("Expires",); Response.AddHeader ("Cache-control", "No-cache");/the browser and cache server should not cache page information Response.AddHeader ("Cache-control", " No-store ")//Request and response information should not be stored on each other's disk system; Response.AddHeader (" Cache-control "," must-revalidate "); *///on each request of the client,
The proxy server must want the server to verify that the cache is obsolete; System.out.println ("Into servlet");
Response.getwriter (). Write ("Welcome to my homepage");  }
}

If you need to set the cache on an HTML page, add the following statement to the

<meta http-equiv= "Pragma" content= "No-cache" >
<meta http-equiv= "Cache-control" content= "No-cache" >

Attached: Meta function in HTML page

Meta is a response header message that is used to simulate an HTTP protocol in an HTML document. Meta tags are useful for

  Name property

1, <meta name= "generator" contect= "> to describe the build tools (such as Microsoft FrontPage 4.0);

2, <meta name= "KEYWords" contect= "" > to the search engine to explain the keywords of your web page;

3, <meta name= "DEscription" contect= "" > Tell the search engine your site's main content;

4, <meta name= "Author" contect= "Your Name" > tell the search engine to make the author of your site;

5, <meta name= "Robots" contect= "All|none|index|noindex|follow|nofollow" >

  The properties are described below:

Set to all: The file will be retrieved and the link on the page can be queried;

Set to None: The file will not be retrieved and the link on the page cannot be queried;

Set to index: file will be retrieved;

Set to follow: the link on the page can be queried;

Set to NOINDEX: The file will not be retrieved, but the link on the page can be queried;

Set to Nofollow: The file will not be retrieved and the link on the page can be queried.

  Http-equiv Property

1, <meta http-equiv= "Content-type" contect= "text/html" charset=gb_2312-80 "> and <meta http-equiv=" Content-language "contect=" ZH-CN ">" to explain the text and language used to make the homepage;

Also such as English is iso-8859-1 character set, there are BIG5, Utf-8, Shift-jis, Euc, Koi8-2 and other character sets;

2, <meta http-equiv= "Refresh" contect= "N;url=http://yourlink" > Time to make the Web page in the specified times N, jump to the page http://yourlink;

3, <meta http-equiv= "Expires" contect= "mon,12 May 2001 00:20:00 GMT" > can be used to set the expiration time of the Web page, once expired must be called back to the server. It is important to note that the GMT time format must be used;

4, <meta http-equiv= "Pragma" contect= "No-cache" > is used to set the browser from the local computer cache to access the content of the page, set once away from the Web page can not be removed from the cache;

5, <meta http-equiv= "Set-cookie" contect= "mon,12 May 2001 00:20:00 GMT" >cookie set, if the page expires, save the cookie will be deleted. Attention must also be paid to the use of GMT time format;

6, <meta http-equiv= "Pics-label" contect= "> Web rating, there is a content setting in Internet Options for IE to prevent browsing of restricted sites, And the limit level of the website is set by the meta attribute;

7, <meta http-equiv= "Windows-target" contect= "_top" > Mandatory page in the current window with a separate page display, you can prevent their own web page by others as a frame page call;

8, <meta http-equiv= "Page-enter" contect= "Revealtrans (duration=10,transtion=)" > and <meta http-equiv= " Page-exit "contect=" Revealtrans (duration=20,transtion=6) > sets the special effects of entering and leaving the page, which is "format/page Transitions" in FrontPage. However, the added page can not be a frame page.

The above is a small set of pages to introduce the cache and do not cache settings and HTML page meta role of the relevant knowledge, hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.