The Example JSP Pages

This chapter describes the tasks involved in defining simple tags. We illustrate the tasks using excerpts from the JSP version of the Duke's Bookstore application discussed in The Example JSP Pages (page 101), rewritten here to take advantage of several custom tags:

  • A catalog tag for rendering the book catalog

  • A shipDate tag for rendering the ship date of an order

  • A template library for ensuring a common look and feel among all screens and composing screens out of content chunks

The tutorial-template tag library defines a set of tags for creating an application template. The template is a JSP page that has placeholders for the parts that need to change with each screen. Each of these placeholders is referred to as a parameter of the template. For example, a simple template might include a title parameter for the top of the generated screen and a body parameter to refer to a JSP page for the custom content of the screen. The template is created using a set of nested tagsdefinition, screen, and parameterthat are used to build a table of screen definitions for Duke's Bookstore. An insert tag to insert parameters from the table into the screen.

Figure 71 shows the flow of a request through the following Duke's Bookstore web components:

  • template.jsp, which determines the structure of each screen. It uses the insert tag to compose a screen from subcomponents.

  • screendefinitions.jsp, which defines the subcomponents used by each screen. All screens have the same banner but different title and body content (specified by the JSP Pages column in Figure 41).

  • Dispatcher, a servlet, which processes requests and forwards to template.jsp.

Figure 71. Request Flow through Duke's Bookstore Components

The source code for the Duke's Bookstore application is located in the <INSTALL>/javaeetutorial5/examples/web/bookstore3/ directory created when you unzip the tutorial bundle (see About the Examples, page xxxiv).

To deploy and run the application using NetBeans 5.5, follow these steps:


Perform all the operations described in Accessing Databases from Web Applications (page 55).


In NetBeans 5.5, select FileOpen Project.


In the Open Project dialog, navigate to:



Select the bookstore3 folder.


Select the Open as Main Project checkbox and the Open Required Projects checkbox.


Click Open Project Folder.


In the Projects tab, right-click the bookstore3 project, and select Deploy Project.


To run the application, open the bookstore URL http://localhost:8080/bookstore3/bookstore.

To deploy and run the application using ant follow these steps:


In a terminal window, go to <INSTALL>/javaeetutorial5/examples/web/bookstore3/.


Run ant. This target will spawn any necessary compilations, copy files to the <INSTALL>/javaeetutorial5/examples/web/bookstore3/build/ directory, and create a WAR file and copy it to the <INSTALL>/javaeetutorial5/examples/web/bookstore3/dist/ directory.


Start the Application Server.


Perform all the operations described in Creating a Data Source in the Application Server (page 56).


To deploy the example, run ant deploy. The deploy target outputs a URL for running the application. Ignore this URL, and instead use the one shown in the next step.


To run the application, open the bookstore URL http://localhost:8080/bookstore3/bookstore

To learn how to configure the example, refer to the web.xml file, which includes the following configurations:

  • A display-name element that specifies the name that tools use to identify the application.

  • A context-param element that specifies the JSTL resource bundle base name.

  • A listener element that identifies the ContextListener class used to create and remove the database access.

  • A servlet element that identifies the Dispatcher instance.

  • A set of servlet-mapping elements that map Dispatcher to URL patterns for each of the JSP pages in the application.

  • Nested inside a jsp-config element is a jsp-property-group element, which sets the properties for the group of pages included in this version of Duke's Bookstore. See Setting Properties for Groups of JSP Pages (page 149) for more information.

To run the example, open the bookstore URL http://localhost:8080/bookstore3/bookstore.

See Troubleshooting (page 62) for help with diagnosing common problems.

The JavaT EE 5 Tutorial
The JavaT EE 5 Tutorial
Year: 2004
Pages: 309 © 2008-2017.
If you may any questions please contact us: