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 :






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


Allow: GET, HEAD


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


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


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;



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

Content-Encoding: gzip


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

Content-Language: da


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


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

response document.

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


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


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


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.



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.




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


This header specifies a cookie associated with the page.

Set-Cookie: UserID=JohnDoe; Max

Age=3600; Version=1

Pr.Pg border                                              Next Pg