| < Day Day Up > |
|
The <bean:header /> tag functions exactly like <bean:cookie />, except that it retrieves its values from the named request header. Once the tag has the header values, it creates a java.lang.String or java.lang.String[] attribute and stores it in the PageContext.
If the named header cannot be located and no default value is given, then a request-time exception will be thrown. The <bean:header /> tag has a body type of JSP and supports four attributes, described in Table 20.3.
Attribute | Description |
---|---|
id | Represents the name of the scripting variable that will be exposed as a page scoped attribute. (Required) |
name | Identifies the name of the HTTP header being retrieved. (Required) |
multiple | If not null, causes a String[] containing all of the header values for the named HTTP header to be returned as opposed to a single header. If the multiple attribute is not null and there is only a single HTTP header, then the first or [0] element of the String[] will contain the retrieved value. (Optional) |
value | Specifies the default value to return and store in the name object, if the named header is not found. (Optional) |
An example of using the <bean:header /> tag is shown here:
<bean:header name="Cache-Control" value="Cache-Control Not Found" />
In this example, we are looking for a HTTP header, Cache-Control. If the Cache-Control header exists, then a String object containing the retrieved value is created and stored in the page; otherwise, a String object containing the String named in the value attribute--Cache-Control Not Found in this example--is created and stored in the page.
| < Day Day Up > |
|