SRV.6.2 Headers


A servlet can set headers of an HTTP response via the following methods of the HttpServletResponse interface:

  • setHeader

  • addHeader

The setHeader method sets a header with a given name and value. If a previous header exists, it is replaced by the new header. In the case where a set of header values exist for the given name , all values are cleared and replaced with the new value.

The addHeader method adds a header value to the set of headers with a given name. If there are no headers already associated with the given name, this method will create a new set.

Headers may contain data that is better expressed as an int or a Date object. The following convenience methods of the HttpServletResponse interface allow a servlet to set a header using the correct formatting for the appropriate data type:

  • setIntHeader

  • setDateHeader

  • addIntHeader

  • addDateHeader

In order to be successfully transmitted back to the client, headers must be set before the response is committed. Any headers set after the response is committed will be ignored by the servlet container.



Java 2 Platform, Enterprise Edition. Platform and Component Specifications
Java 2 Platform, Enterprise Edition: Platform and Component Specifications
ISBN: 0201704560
EAN: 2147483647
Year: 2000
Pages: 399

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net