Pr.Pg Next Pg

Server HTTP Response tutorials

  • Web server sends response with one or more response headers including the document content. You can use HTTP response headers to specify cookies, to instruct the browser to reload the page after a specified interval, setting content type, setting content length etc.

  • In general you can set header by using setHeader() method of HttpServletResponse.

 

SetHeader(String headerName, String headerValue)

  • It sets the response header with specified name to the given value. There is another method holds date and int - setDateHeader(String header, long milliseconds) andsetIntHeader(String header, int headerValue).

  • Below are the list of some Http Response headers :

 

Header

Description

Example

Allow

This header specifies the request methods (GET, POST, etc.) that the server

supports.

Allow: GET, HEAD

Cache-Control

This header specifies the circumstances in which the response document can safely be cached. It can have values public, private orno-cache etc. Public means document is cacheable, Private means document is for a single user and can only be stored in private (nonshared) caches and no-cache means document should never be cached.

Cache-Control: max-age=3600

Connection

This header instructs the browser whether to use persistent in HTTP connections or not. A value of close instructs the browser not to use persistent HTTP connections and keep-alive means using persistent connections.

Connection: close

Content-Disposition

This header lets you request that the browser ask the user to save the response to disk in a file of the given name.

Content-Disposition: attachment;

filename="fname.ext"

Content-Encoding

This header specifies the way in which the page was encoded during transmission.

Content-Encoding: gzip

Content-Language

This header signifies the language in which the document is written. For example en, en-us, ru, etc.

Content-Language: da

Content-Length

This header indicates the number of bytes in the response. This information is needed only if the browser is using a persistent (keep-alive) HTTP connection.

Content-Length: 348

Content-Type

This header gives the MIME (Multipurpose Internet Mail Extension) type of the

response document.

Content-Type: text/html; charset=utf-8

Expires

This header specifies the time at which the content should be considered out-of-date and thus no longer be cached.

Expires: Thu, 01 Dec 1994 16:00:00 GMT

Last-Modified

This header indicates when the document was last changed. The client can then cache the document and supply a date by an If-Modified-Since request header in later requests.

Last-Modified: Tue, 15 Nov 1994

12:45:26 GMT

Location

This header should be included with all responses that have a status code in the 300s. This notifies the browser of the document address. The browser automatically reconnects to this location and retrieves the new document.

Location: http://www.cbtsam.com/cl1/cbtsam-cl1-001.php

Refresh

This header specifies how soon the browser should ask for an updated page. You can specify time in number of seconds after which a page would be refreshed.

Refresh:5;

url=http://www.cbtsam.com/cl1/cbtsam-cl1-001.php

Retry-After

This header can be used in conjunction with a 503 (Service Unavailable) response to tell the client how soon it can repeat its request.

Retry-After: 120

Set-Cookie

This header specifies a cookie associated with the page.

Set-Cookie: UserID=JohnDoe; Max

Age=3600; Version=1

Pr.Pg border                                              Next Pg