SRV.5.3 Headers


A servlet can access the headers of an HTTP request through the following methods of the HttpServletRequest interface:

  • getHeader

  • getHeaders

  • getHeaderNames

The getHeader method allows access to the value of a header given the name of the header. Multiple headers, such as the Cache-Control header, can be present in an HTTP request. If there are multiple headers with the same name in a request, the getHeader method returns the first header contained in the request. The getH eaders method allows access to all the header values associated with a particular header name returning an Enumeration of String objects.

Headers may contain data that is better expressed as an int or a Date object. The following convenience methods of the HttpServletRequest interface provide access to header data in one of these formats:

  • getIntHeader

  • getDateHeader

If the getIntHeader method cannot translate the header value to an int , a Num berFormatException is thrown. If the getDateHeader method cannot translate the header to a Date object, an IllegalArgumentException is thrown.



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