Document Information

Preface

Part I Introduction

1.  Overview

2.  Using the Tutorial Examples

Part II The Web Tier

3.  Getting Started with Web Applications

4.  Java Servlet Technology

5.  JavaServer Pages Technology

What Is a JSP Page?

A Simple JSP Page Example

The Example JSP Pages

The Life Cycle of a JSP Page

Translation and Compilation

Execution

Buffering

Handling JSP Page Errors

Creating Static Content

Response and Page Encoding

Creating Dynamic Content

Using Objects within JSP Pages

Using Implicit Objects

Using Application-Specific Objects

Using Shared Objects

Unified Expression Language

Immediate and Deferred Evaluation Syntax

Immediate Evaluation

Deferred Evaluation

Value and Method Expressions

Value Expressions

Method Expressions

Defining a Tag Attribute Type

Deactivating Expression Evaluation

Literal Expressions

Resolving Expressions

Process of Expression Evaluation

EL Resolvers

Implicit Objects

Operators

Reserved Words

Examples of EL Expressions

Functions

Using Functions

Defining Functions

JavaBeans Components

JavaBeans Component Design Conventions

Creating and Using a JavaBeans Component

Setting JavaBeans Component Properties

Retrieving JavaBeans Component Properties

Using Custom Tags

Declaring Tag Libraries

Including the Tag Library Implementation

Reusing Content in JSP Pages

Transferring Control to Another Web Component

jsp:param Element

Including an Applet

Further Information about JavaServer Pages Technology

6.  JavaServer Pages Documents

7.  JavaServer Pages Standard Tag Library

8.  Custom Tags in JSP Pages

9.  Scripting in JSP Pages

10.  JavaServer Faces Technology

11.  Using JavaServer Faces Technology in JSP Pages

12.  Developing with JavaServer Faces Technology

13.  Creating Custom UI Components

14.  Configuring JavaServer Faces Applications

15.  Internationalizing and Localizing Web Applications

Part III Web Services

16.  Building Web Services with JAX-WS

17.  Binding between XML Schema and Java Classes

18.  Streaming API for XML

19.  SOAP with Attachments API for Java

Part IV Enterprise Beans

20.  Enterprise Beans

21.  Getting Started with Enterprise Beans

22.  Session Bean Examples

23.  A Message-Driven Bean Example

Part V Persistence

24.  Introduction to the Java Persistence API

25.  Persistence in the Web Tier

26.  Persistence in the EJB Tier

27.  The Java Persistence Query Language

Part VI Services

28.  Introduction to Security in the Java EE Platform

29.  Securing Java EE Applications

30.  Securing Web Applications

31.  The Java Message Service API

32.  Java EE Examples Using the JMS API

33.  Transactions

34.  Resource Connections

35.  Connector Architecture

Part VII Case Studies

36.  The Coffee Break Application

37.  The Duke's Bank Application

Part VIII Appendixes

A.  Java Encoding Schemes

B.  About the Authors

Index

 

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 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 using NetBeans IDE, follow these steps:

  1. In NetBeans IDE, expand your project’s folder in the Projects pane.

  2. Expand the Web Pages node and then the WEB-INF node.

  3. Double-click web.xml to open it in the editor pane.

  4. Click Pages at the top of the editor pane.

  5. Click Add JSP Property Group.

  6. In the Add JSP Property Group dialog:

    1. Enter a name for the JSP property group in the Display Name field.

    2. Enter a URL pattern (a regular expression, such as *.jsp) or click Browse to indicate to which page or set of pages to apply the properties specified by the JSP property group.

    3. Click OK.

Instead of performing the preceding steps, you can define a JSP property group 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. Include a jsp-config element if the deployment descriptor doesn’t already have one.

  4. Add a jsp-property-group element inside the jsp-config element.

  5. Add a display-name element inside the jsp-property-group element and give it a name.

  6. 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 with a Servlet 2.4 descriptor is to evaluate EL expressions; this automatically provides the default that most applications want. The default mode for JSP pages delivered using a descriptor from Servlet 2.3 or before is to ignore EL expressions; this provides backward compatibility. For tag files (see Encapsulating Reusable Content Using Tag Files), 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 doing one of the following:

  • If you are using the Pages section of the web.xml editor pane in NetBeans IDE:

    1. Expand the JSP Property Group node.

    2. Select the Ignore Expression Language check box.

  • If you are editing the web.xml file by hand, add an el-ignored element to the jsp-property-group element in the deployment descriptor and set it to true.

Table 5-8 summarizes the EL evaluation settings for JSP pages.

Table 5-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 5-9 summarizes the EL evaluation settings for tag files.

Table 5-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 using the JSP property group configuration in the deployment descriptor by doing one of the following:

  • If you are using the Pages section of the web.xml editor pane in NetBeans IDE:

    1. Expand the JSP Property Group node.

    2. Enter the page encoding in the Page Encoding field.

  • If you are editing the web.xml file by hand, add a page-encoding element to the jsp-property-group element in the deployment descriptor and set it 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. In NetBeans IDE, expand your project’s folder in the Projects pane.

  2. Expand the Web Pages node and then the WEB-INF node.

  3. Double-click web.xml to open it in the editor pane.

  4. Click Pages at the top of the editor pane.

  5. Add a new JSP property group if you haven’t already (see Setting Properties for Groups of JSP Pages) 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) 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.

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.