Meta tag in HTML header
In server response, we can use response.setHeader() to set the meta information in header of a HTML page. The usage is response.setHeader(name,context);
meta is used to simulate the response header of HTTP protocol in HTML page. It should be put between the <head> and </head> tag.
1. <meta name="Generator" content="" > <!--This is to specify the tool which generates this page such as Microsoft FrontPage 4.0 etc -->
2. <meta name="keywords" content=""> <!-- To tell the search engine what keywords your page contains -->
3.<meta name="description" content=""> <!-- To tell the search engine the main contents in the page -->
4. <meta name="author" content=""> <!-- To tell the search engine author of this page-->
5. <meta name="robots" content="all|none|index|noindex|follow|nofollow" >
- all : Page will be indexed and links can be followed
- none: Page cannot be indexed and links on the page cannot be followed
- index : Page can be indexed
- follow : Links on the page can be followed
- noindex : Page cannot be indexed but the links on the page can be followed
- nofollow : Links on the page should not be followed
1.Below two can be used to specify the content type and content language. We can have ISO-8859-1,BIG5、utf-8、shift-Jis、Euc、Koi8-2
<meta http-equiv="Content-Type" content="text/html";charset=gb_2312-80">
<meta http-equiv="Content-Language" content="zh-CN">
2. Below tag can specify which page to redirect to after n seconds
<meta http-equiv="Refresh" content="n;url=http://yourlink/">
3. Below tag can specify the expiration date of the page, if the page expires, the page will be requested from server again.
<meta http-equiv="Expires" content="Mon,12 May 2001 00:20:00 GMT">
4. Below tag prohibits the browser to fetch the page from the cache. Once user leaves this page, it cannot be fetched from cache
<meta http-equiv="Pragma" content="no-cache">
5. Set cookie, if page is expired, the cookie will be removed as well. Note, we have to use GMT time here.
<meta http-equiv="set-cookie" content="Mon,12 May 2001 00:20:00 GMT">
6. Below tag specifies the rating scheme of the page. In Internet Options on IE we can specify the security levels to limit the page content.
<meta http-equiv="Pics-label" content="">
7. Force the page to be opened in a separate window, this can prevent others opening the page in a frame.
<meta http-equiv="windows-Target" content="_top">
8. Set the effects after entering this page and before leaving this page.
<meta http-equiv="Page-Enter" content="revealTrans(duration=10,transtion= 50)"> <meta http-equiv="Page-Exit" content="revealTrans(duration=20，transtion=6)">
This is used to prevent the browser from caching your dynamic content generated by a JSP or Servlet.
You set this attribute in the HTTP header of the response object which would tell the browser not to cache this content. So every time you request the page again, the browser would make a new request, instead of showing you a cached page.
2. Server side to control AJAX page cache
response.setHeader( "Pragma", "no-cache" ); response.addHeader( "Cache-Control", "must-revalidate" ); response.addHeader( "Cache-Control", "no-cache" ); response.addHeader( "Cache-Control", "no-store" ); response.setDateHeader("Expires", 0);
It will not work by solely using xmlhttp.setRequestHeader("Cache-Control","no-cache")
3. Cache-Control header
Cache-Control specifies the cache mechanism to be followed while requesting and responding. The request cache directives can be : no-cache、no-store、max-age、max-stale、min-fresh、only-if- cached. The response cache directives can be : public、private、no-cache、no-store、no-transform、must- revalidate、proxy-revalidate、max-age.
public: Indicates that the response MAY be cached by any cache, even if it would normally be non-cacheable or cacheable only within a non- shared cache. (See also Authorization, section 14.8, for additional details.)
private: Indicates that all or part of the response message is intended for a single user and MUST NOT be cached by a shared cache. This allows an origin server to state that the specified parts of the
response are intended for only one user and are not a valid response for requests by other users. A private (non-shared) cache MAY cache the response.
Note: This usage of the word private only controls where the response may be cached, and cannot ensure the privacy of the message content.
no-cache : If the no-cache directive does not specify a field-name, then a cache MUST NOT use the response to satisfy a subsequent request without successful revalidation with the origin server. This allows an origin server to prevent caching even by caches that have been configured to return stale responses to client requests.
If the no-cache directive does specify one or more field-names, then a cache MAY use the response to satisfy a subsequent request, subject to any other restrictions on caching. However, the specified field-name(s) MUST NOT be sent in the response to a subsequent request without successful revalidation with the origin server. This allows an origin server to prevent the re-use of certain header fields in a response, while still allowing caching of the rest of the response.
no-store : The purpose of the no-store directive is to prevent the inadvertent release or retention of sensitive information (for example, on backup tapes). The no-store directive applies to the entire message, and MAY be sent either in a response or in a request. If sent in a request, a cache MUST NOT store any part of either this request or any response to it. If sent in a response, a cache MUST NOT store any part of either this response or the request that elicited it. This directive applies to both non- shared and shared caches. "MUST NOT store" in this context means that the cache MUST NOT intentionally store the information in non-volatile storage, and MUST make a best-effort attempt to remove the information from volatile storage as promptly as possible after forwarding it.
max-age : Indicates that the client is willing to accept a response whose age is no greater than the specified time in seconds. Unless max- stale directive is also included, the client is not willing to accept a stale response.
min-fresh : Indicates that the client is willing to accept a response whose freshness lifetime is no less than its current age plus the specified time in seconds. That is, the client wants a response that will still be fresh for at least the specified number of seconds.
max-stale : Indicates that the client is willing to accept a response that has exceeded its expiration time. If max-stale is assigned a value, then the client is willing to accept a response that has exceeded its expiration time by no more than the specified number of seconds. If no value is assigned to max-stale, then the client is willing to accept a stale response of any age.
A young Programmer and his Project Manager board a train headed through the mountains on its way to Wichita. They can find no place to sit except for two seats right across the aisle from a young woman and her grandmother. After a while, it is obvious that the young woman and the young programmer a