The HTML HTTP protocol header information controls the cache information of the page in several places, including the browser side, the intermediate cache server side (such as squid, etc.), and the Web server side. This article discusses the cache situation of HTML pages with cache control information in the header information (the HTML pages generated by JSP/Servlets are also HTML pages) in the intermediate cache server.
The header keywords about cache in the HTTP protocol include Cache-Control (HTTP1.1), Pragma (HTTP1.0), last-Modified, Expires, etc.
In HTTP 1.0, page cache is controlled through Pragma , and you can set: Pragma or no-cache. There are many articles on the Internet explaining how to prevent the browser or intermediate cache server from cache pages. The value is usually set to no-cache, but this value is not so safe. Usually, Expires is set to 0 to achieve the goal. However, if we deliberately need the browser or cache server to cache our page, this value must be set to Pragma.
In HTTP 1.1, Cache-Control is enabled to control the cache of pages. Here are a few commonly used parameters:
•no-cache, neither browser nor cache server should cache page information;
•public, both the browser and the cache server can cache page information;
•no-store, neither request nor response information should be stored in the other party's disk system;
• must-revalidate, for each request from the client, the proxy server must want the server to verify that the cache is outdated;
Last-Modified only the last generation time of the page, GMT format;
Expires expired limit value, GMT format, means that the browser or cache server must obtain new page information from the real server after this time point;
The above two values are set to character-type GMT format in JSP, and cannot take effect, so the long type is set 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 {@Overridepublic void service(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {response.setContentType("text/html");//The servlet page is not cached by default//This page allows cache on the browser side or in the cache server, with a time limit of seconds. //If you re-enter the page within seconds, you will not enter the servlet's java.util.Date date = new java.util.Date(); response.setDateHeader("Last-Modified", date.getTime()); //Last-Modified: The last generation time of the page response.setDateHeader("Expires", date.getTime()+); //Expires: The expiration limit response.setHeader("Cache-Control", "public"); //Cache-Control controls whether the page is cached, public: Both the browser and the cache server can cache page information; response.setHeader("Pragma", "Pragma"); //Pragma: Set whether the page is cached. If it is Pragma, it will be cached. If it is no-cache, it will not be cached.//The browser or cache server is not allowed to cache the current page information. /*response.setHeader( "Pragma", "no-cache" ); response.setDateHeader("Expires", ); response.addHeader( "Cache-Control", "no-cache" );//Neither the browser nor the cache server should cache page information response.addHeader( "Cache-Control", "no-store" );//Non of the request and response information should be stored in the other party's disk system; response.addHeader( "Cache-Control", "must-revalidate" );*////For each request from the client, the proxy server must want the server to verify that the cache is out of date; System.out.println("entered servlet"); response.getWriter().write("Welcome to my homepage");}} If you need to set the cache on the html page, add the following statement to the <head> tag:
<meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="">
Attachment: The role of meta in html page
meta is used to simulate the response header of the HTTP protocol in HTML documents. The meta tag is used in the <head> and</head> of web pages. The meta tag is of many uses. There are two properties of meta: name and http-equiv. The name attribute is mainly used to describe web pages, corresponding to content (web page content), so that search engine robots can search and classify (currently, almost all search engines use online robots to automatically search meta values to classify web pages). The most important of these are description (the description of the site on search engines) and keywords (categorized keywords), so you should add a meta value to each page. The most commonly used ones are the following:
name attribute
1. <meta name="Generator" contact=""> is used to illustrate the generation tool (such as Microsoft FrontPage 4.0), etc.;
2. <meta name="KEYWords" contact="">Explain the keywords of your web page to search engines;
3. <meta name="DEscription" contact="">Tell search engines the main content of your site;
4. <meta name="Author" contact="Your Name">Tell search engines the author of the production of your site;
5. <meta name="Robots" contact= "all|none|index|noindex|follow|nofollow">
The attributes are described as follows:
Set to all: the file will be retrieved and the links on the page can be queried;
Set to none: the file will not be retrieved, and the links on the page cannot be queried;
Set as index: the file will be retrieved;
Set to follow: The links on the page can be queried;
Set to noindex: the file will not be retrieved, but the links on the page can be queried;
Set to nofollow: the file will not be retrieved, and the links on the page can be queried.
http-equiv attribute
1. <meta http-equiv="Content-Type" contact="text/html";charset=gb_2312-80"> and <meta http-equiv="Content-Language" contact="zh-CN"> are used to explain the text and language used in homepage production;
For example, the English is the ISO-8859-1 character set, and there are also BIG5, utf-8, shift-Jis, Euc, Koi8-2 and other character sets;
2. <meta http-equiv="Refresh" contact="n;url=http://yourlink">Changes the web page to the page within the specified time n;
3. <meta http-equiv="Expires" contact="Mon,12 May 2001 00:20:00 GMT"> can be used to set the expiration time of the web page. Once it expires, it must be called on the server again. It should be noted that the GMT time format must be used;
4. <meta http-equiv="Pragma" contact="no-cache"> is used to set the browser to prohibit the page content from the local cache, and once the web page is left, it cannot be called out from the cache again;
5. <meta http-equiv="set-cookie" contact="Mon,12 May 2001 00:20:00 GMT">cookie setting. If the web page expires, the saved cookies will be deleted. It is also necessary to use the GMT time format;
6. <meta http-equiv="Pics-label" contact="">Web page level rating, there is a content setting in the Internet options of IE, which can prevent browsing some restricted websites, and the restriction level of the website is set through the meta attribute;
7. <meta http-equiv="windows-Target" contact="_top">Forcing the page to be displayed as an independent page in the current window, which can prevent your web page from being called by others as a frame page;
8. <meta http-equiv="Page-Enter" contact="revealTrans(duration=10,transtion=50)"> and <meta http-equiv="Page-Exit" contact="revealTrans(duration=20,transtion=6)"> set the special effect when entering and leaving the page. This function is the "Format/Web Page Transition" in FrontPage, but the added page cannot be a frame page.
The above is the relevant knowledge about the cache and non-cache settings of the page and the role of meta in the html page that the editor introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!