Thursday, 7 February 2013

Headers | Java Servlets Tutorial pdf

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 returns a header given the name of the header. There can be multiple headers with the same name, e.g. Cache-Control headers, in an HTTP request. If there are multiple headers with the same name, the getHeader method returns the first header in the request. The getHeaders method allows access to all the header values associated with a particular header name, returning an Enumeration of String objects.
Headers may contain String representations of int or Date data. The following convenience methods of the HttpServletRequest interface provide access to header data in a one of these formats:
=> getIntHeader
=> getDateHeader
If the getIntHeader method cannot translate the header value to an int, a NumberFormatException is thrown. If the getDateHeader method cannot translate the header to a Date object, an IllegalArgumentException is thrown.

No comments: