May 27, 2021 HTTP
The HTTP request header provides information about the request, response, or other sending entity. In this section, we'll cover http response header information in detail.
Answer head | Description |
---|---|
Allow | Which request methods (e.g. GET, POST, etc.) are supported by the server. |
Content-Encoding | The encode method of the document. T he content type specified by the Content-Type header can only be obtained after decoding. U sing gzip to shrink documents can significantly reduce the download time of HTML documents. J ava's GZIPOutputStream makes gzip compression easy, but only Netscape on Unix and IE 4 and IE 5 on Windows support it. Therefore, Servlet should check whether the browser supports gzip by looking at the Access-Encoding header ("Accept-Encoding"), return a gzip-compressed HTML page for a gzip-supported browser, and return a normal page for other browsers. |
Content-Length | Represents the length of the content. T his data is only required if the browser uses a persistent HTTP connection. If you want to take advantage of persistent connectivity, you can write the output document to ByteArrayOutputStram, check its size when you're done, put the value in the Content-Length header, and finally send the content via byteArrayStream.writeTo (response.getOutputStream)). |
Content-Type |
Indicates what MIME type the subsequent document belongs to. S
ervlet defaults to text/plain, but usually needs to be explicitly specified as text/html. B
ecause Constant-Type is often set up, httpServletResponse provides a dedicated method, setContentType.
|
Date | The current GMT time. You can set this header with setDateHeader to avoid the hassle of converting the time format. |
Expires | When should I think the document has expired and stop caching it? |
Last-Modified | The last time the document was changed. C ustomers can provide a date through the If-Modified-Since request header, which will be treated as a conditional GET, and only documents that have changed later than the specified time will be returned, otherwise a 304 (Not Modified) status will be returned. Last-Modified can also be set up using the setDateHeader method. |
Location | Indicates where the customer should go to extract the document. Location is usually not set directly, but through the EndingRedirect method of httpservletResponse, which also sets the status code to 302. |
Refresh |
Indicates how long the browser should refresh the document in seconds. I
n addition to refreshing the current document, you can also use setHeader ("Refresh," "5; T
he URL is http://host/path) for the browser to read the specified page.
Note that this feature is usually done by setting up the HTML page HEAD <META HTTP-EQUIV," "Refresh" CONTENT=5; T he URL is http://host/path"> because automatic refresh or redirection is important for HTML writers who cannot use CGI or Servlet. H owever, it is more convenient for the Servlet to set up the Refresh head directly. Noterefresh means "brush the new page or visit the specified page after N seconds" instead of "refreshing this page or visiting the specified page every N seconds." T herefore, continuous refresh requires sending a Refresh header at a time, while sending a 204 status code prevents the browser from continuing to refresh, whether using the Refresh header or the <META HTTP-EQUIV "Refresh" ... > 。 Note that the Refresh header is not part of the official HTTP 1.1 specification, but is an extension, but both Netscape and IE support it. |
Server | The name of the server. Servlets generally do not set this value, but are set by the Web server itself. |
Set-Cookie | Set cookies associated with the page. I nstead of using response.setHeader ("Set-cookies,"...), Servlet should use the special method add cookies provided by HttpServletResponse. See below for a discussion of cookie settings. |
WWW-Authenticate |
What type of authorization information should the customer provide in the Ausorization header? T
his header is required in an answer that contains a 401 (Multiple) status line. F
or example, response.setHeader ("WWW-Authenticate," "BASIC realm").
Note that servlets generally do not handle this, but rather have a dedicated mechanism for Web servers to control access to password-protected pages (e.g., .htacces). |