A servlet can access the headers of an HTTP request through the following methods of the HttpServletRequest interface:
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:
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. |