开发者

Set header in HttpServletResponse and Html <head> tag is the same?

In HttpServletResponse, invocation of setHeader() method is the same as we set value in html <head> tag?

Java Code:

response.setHeader("Pragma", "no-cache");

response.setIntHeader("Expires", -1);

Html:

<HTML><HEAD>
<META HTTP-EQUIV="Pragma" CONTENT="no-cac开发者_Go百科he">
<META HTTP-EQUIV="Expires" CONTENT="-1">
</HEAD><BODY>
</BODY>
</HTML>

Are both of them the same?


No.

Unlike META tags in HTML documents, HTTP response headers set by the HttpServletResponse methods can be interpreted and acted upon by any of the nodes in the network, that exist between the client and the server. Typically these are proxies, which do not bother with the content of the HTML documents. The reason such elements can act on these headers, is that the HTTP response headers apply not only to the client(browser) but also to any of the intermediaries; the HTTP specification allows for interpretation of headers by intermediaries.

If you want all elements in a network to obey the cache headers, which you are intending to set (in the HTML document), then specify the HTTP response headers (using the HttpServletResponse object). All intermediaries are expected to obey these headers.

Only browsers tend to act on the META tags, for only they parse the HTML document; in other words, the META tags will determine the expiry settings of a document for the browser local cache, and not of the proxy caches.

Related resources

  1. Caching Tutorial for Web Authors and Webmasters. Refer the section on HTML Meta Tags vs. HTTP Headers.
  2. Caching in HTTP. Straight from the HTTP 1.1 specification. The behavior of the client, origin server and intermediaries is specified here.
  3. Meta data in the HTML 4.01 Specification. The HTML specification, quite obviously states that HTTP servers may use the property name specified by the http-equiv attribute to create an [RFC822]-style header in the HTTP response. Servers do not seem to adhere to this, since the word 'may' indicates that this is an optional feature.


No,

HTTP headers are RFC 2616 headers, so when client gets response from the server, it translate these HTTP response headers first.

HTML data are just enity body in the HTTP message, and only the releavant interpreter (e.g. browser) can translate it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜