Home | Download | PDF | API | FAQ | Search | Feedback | History

> ## Setting Properties for Groups of JSP Pages

> It is possible to specify certain properties for a group of JSP pages:

> - Expression language evaluation
> - Treatment of scripting elements (see Disabling Scripting, page 253)
> - Page encoding
> - Automatic prelude and coda includes

> A JSP property group is defined by naming the group and specifying one or more URL patterns; all the properties in the group apply to the resources that match any of the URL patterns. If a resource matches URL patterns in more than one group, the pattern that is most specific applies. To define a property group in a deployment descriptor, follow these steps:

> 1. Include a `jsp-config` element if the deployment descriptor doesn't already have one.
> 2. Add a `jsp-property-group` element inside the `jsp-config` element.
> 3. Add a `display-name` element inside the `jsp-property-group` element and give it a name.
> 4. Add a `url-pattern` element inside the `jsp-property-group` element and give it a URL pattern (a regular expression, such as `*.jsp`).

> The following sections discuss the properties and explain how they are interpreted for various combinations of group properties, individual page directives, and web application deployment descriptor versions.

> #### Deactivating EL Expression Evaluation

> Each JSP page has a default mode for EL expression evaluation. The default value varies depending on the version of the web application deployment descriptor. The default mode for JSP pages delivered using a Servlet 2.3 or earlier descriptor is to ignore EL expressions; this provides backward compatibility. The default mode for JSP pages delivered with a Servlet 2.4 descriptor is to evaluate EL expressions; this automatically provides the default that most applications want. For tag files (see Encapsulating Reusable Content Using Tag Files, page 204), the default is to always evaluate expressions.

> You can override the default mode through the `isELIgnored` attribute of the `page` directive in JSP pages and through the `isELIgnored` attribute of the `tag` directive in tag files. You can also explicitly change the default mode by adding an `el-ignored` element to the `jsp-property-group` element in the deployment descriptor. Table 4-8 summarizes the EL evaluation settings for JSP pages and their meanings.

> Table 4-8 EL Evaluation Settings for JSP Pages
> JSP Configuration | Page Directive isELIgnored | EL Encountered
> --- | --- | ---
> Unspecified | Unspecified | Evaluated if 2.4 `web.xml` Ignored if <= 2.3 `web.xml`
> `false` | Unspecified | Evaluated
> `true` | Unspecified | Ignored
> Overridden by page directive | `false` | Evaluated
> Overridden by page directive | `true` | Ignored

> Table 4-9 summarizes the EL evaluation settings for tag files and their meanings.

> Table 4-9 EL Evaluation Settings for Tag Files
> Tag Directive isELIgnored | EL Encountered
> --- | ---
> Unspecified | Evaluated
> `false` | Evaluated
> `true` | Ignored

> #### Declaring Page Encodings

> You set the page encoding of a group of JSP pages by adding a `page-encoding` element to the `jsp-property-group` element in the deployment descriptor and setting its value to one of the valid character encoding codes, which are the same as those accepted by the `pageEncoding` attribute of the `page` directive. A translation-time error results if you define the page encoding of a JSP page with one value in the JSP configuration element and then give it a different value in a `pageEncoding` directive.

> #### Defining Implicit Includes

> You can implicitly include preludes and codas for a group of JSP pages by adding items to the Include Preludes and Codas lists. Their values are context-relative paths that must correspond to elements in the web application. When the elements are present, the given paths are automatically included (as in an `include` directive) at the beginning and end, respectively, of each JSP page in the property group. When there is more than one include or coda element in a group, they are included in the order they appear. When more than one JSP property group applies to a JSP page, the corresponding elements will be processed in the same order as they appear in the JSP configuration section.

> For example, the Duke's Bookstore application uses the files `/template/prelude.jspf` and `/template/coda.jspf` to include the banner and other boilerplate in each screen. To add these files to the Duke's Bookstore property group using the deployment descriptor, follow these steps:

> 1. Add a `jsp-property-group` element with name `bookstore2` and URL pattern `*.jsp`.
> 2. Add an `include-prelude` element to the `jsp-property-group` element and give it the name of the file to include, in this case, `/template/prelude.jspf`.
> 3. Add an `include-code` element to the `jsp-property-group` element and give it the name of the file to include, in this case, `/template/coda.jspf`.

> Preludes and codas can put the included code only at the beginning and end of each file. For a more flexible approach to building pages out of content chunks, see A Template Tag Library (page 244).

> #### Eliminating Extra White Space

> Whitespaces included in the template text of JSP pages is preserved by default. This can have undesirable effects. For example, a carriage return added after a `taglib` directive would be added to the response output as an extra line.

> If you want to eliminate the extra white space from the page, you can add a `trim-directive-whitespaces` element to a `jsp-property-group` element in the deployment descriptor and set it to `true`.

> Alternatively, a page author can set the value of the `trimDirectiveWhitespaces` attribute of the `page` directive to true or false. This will override the value specified in the deployment descriptor.

> Custom tag authors can eliminate white space from the output generated by a tag file by setting the `trimDirectiveWhiteSpace` attribute of the `tag` directive to true.