FAQ
History
PreviousHomeNext Search
Feedback
Divider

The Example JSP Pages

This chapter describes the tasks involved in using and defining tags. The chapter illustrates the tasks with excerpts from the JSP version of the Duke's Bookstore application discussed in The Example JSP Pages rewritten to take advantage of two tag libraries: Struts and template. The third section in the chapter, Examples, describes two tags in detail: an iterator tag and the set of tags in the template tag library.

The Struts tag library provides a framework for building internationalized Web applications that implement the Model-View-Controller design pattern. Struts includes a comprehensive set of utility custom tags for handling:

The Duke's Bookstore application uses tags from the Struts bean and logic sublibraries.

The template tag library defines a set of tags for creating an application template. The template is a JSP page with 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 could 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 with a set of nested tags--definition, screen, and parameter--that are used to build a table of screen definitions for Duke's Bookstore and with an insert tag to insert parameters from the table into the screen.

Figure 5-1 shows the flow of a request through the following Duke's Bookstore Web components:

Request Flow Through Duke's Bookstore Components

Figure 5-1 Request Flow Through Duke's Bookstore Components

The template tag library files are located in the directory <INSTALL>/j2eetutorial/examples/web/template. The classes are packaged into a JAR and already included in the WEB-INF/lib directory of all successive versions of the Duke's Bookstore example. To recreate the template library JAR:

  1. In the IDE, mount the filesystem
    <INSTALL>/j2eetutorial/examples/web/template.
  2. Right-click the template node and choose Compile.
  3. Expand the template node.
  4. Create the template JAR.
    1. Right-click the template TLD and choose Create Tag Library JAR.
    2. Right-click the template JAR recipe node and choose Compile.
  5. Expand the template JAR recipe node.

The source for the Duke's Bookstore application is located in the <INSTALL>/j2eetutorial/examples/web/bookstore3 directory.

To deploy and run the example:

  1. In the IDE, mount the filesystem
    <INSTALL>/j2eetutorial/examples/web/bookstore3.
  2. Expand the bookstore3 node.
  3. Right-click the WEB-INF directory and choose Deploy.
  4. Set up the PointBase database as described in Accessing Databases from Web Applications.
  5. Open the bookstore URL http://localhost:80/bookstore3/enter.

To review the deployment settings:

  1. Expand the WEB-INF node.
  2. Select the web.xml file.
  3. Select the Deployment property sheet.
  4. Browse the listener property.
    1. Click the Listeners property and open the property editor.
    2. Notice that the listener class is listeners.ContextListener.
  5. Browse the servlet definition and servlet mappings.
    1. Click the Servlets property and open the property editor.
    2. Notice that the Dispatcher servlet is implemented by the Dispatcher class and that the URLs /enter /catalog, /bookdetails, /showcart, /cashier, and /receipt are mapped to the Dispatcher servlet.
  6. Browse the tag libraries mapping.
    1. Click the Tag Libraries property and open the property editor.
    2. Notice that the relative URI /struts is mapped to /WEB-INF/lib/struts.jar.
    3. Notice that the relative URI /template is mapped to /WEB-INF/lib/template.jar.
  7. Browse the resource references.
    1. Select the Resources Property sheet.
    2. Click the Resource References property and open the property editor.
    3. Note the resource reference named jdbc/BookDB.
Divider
FAQ
History
PreviousHomeNext Search
Feedback
Divider

All of the material in The J2EE Tutorial for the Sun ONE Platform is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.