The Java EE 5 Tutorial

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.

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.