background image

Eliminating ExtraWhite Space

<< Declaring Page Encodings | More on JavaServer Pages Technology >>
<< Declaring Page Encodings | More on JavaServer Pages Technology >>

Eliminating ExtraWhite Space

5. Add a new JSP property group if you haven't already (see
"Setting Properties for Groups of
JSP Pages" on page 179
) and give it the name bookstore2 and the URL pattern *.jsp.
6. Expand the JSP Property Group node.
7. Click the Browse button to the right of the Include Preludes field to locate the file that you
want to include at the beginning of all pages matching the pattern in the URL pattern field.
In this case, you want the /template/prelude.jspf file.
8. Click the Browse button to the right of the Include Codas field to locate the file that you want
to include at the end of all pages matching the URL pattern. In this case, you want the
/template/coda.jspf
file.
Instead of performing the preceding steps, you can add preludes and codas by editing the XML
by hand using NetBeans IDE by doing the following:
1. Perform steps 1 through 3 in the preceding set of steps.
2. Click XML at the top of the editor pane.
3. Add a new JSP property group (see
"Setting Properties for Groups of JSP Pages" on
page 179
) and give it the name bookstore2 and URL pattern *.jsp.
4. 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.
5. Add an include-coda 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"
on page 267
.
Eliminating Extra White Space
White space 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.
To set the trim-directive-whitespaces element to true using NetBeans 5.5, do the following:
1. Open the deployment descriptor file in the editor.
2. Click the Pages button at the top of the editor.
3. Select a JSP property group.
4. Select the Trim Directive Whitespaces check box.
5. Save the deployment descriptor.
Setting Properties for Groups of JSP Pages
The Java EE 5 Tutorial · September 2007
182