The Example JSP Pages



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 (page 404) rewritten to take advantage of two tag libraries: Struts and tutorial-template. The third section in the chapter, Examples (page 453), describes two tags in detail: the iterate tag from Struts and the set of tags in the tutorial-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:

  • HTML forms

  • Templates

  • JavaBeans components

  • Logic processing

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

The tutorial-template tag library defines a set of tags for creating an application template. The template is a JSP page, with place holders 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 an insert tag to insert parameters from the table into the screen.

Figure shows the flow of a request through the Duke's Bookstore Web components:

1. Request Flow Through Duke's Bookstore Components
graphics/16fig01.gif
  • 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).

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

The source for the Duke's Bookstore application is located in the docs/tutorial/examples/web/bookstore3 directory created when you unzip the tutorial bundle (see Running the Examples (page xx)). To build, deploy, and run the example:

  1. Download Struts version 1.0 from

    http://jakarta.apache.org/builds/jakarta-struts/release/v1.0/

  2. Unpack Struts and copy struts-bean.tld, struts-logic.tld, and struts.jar from jakarta-struts-1.0/lib to docs/tutorial/examples/web/bookstore3.

  3. Go to the bookstore3 directory and build and deploy the example by running ant. This runs the default ant target deploy which depends on the buildtarget. The build target will spawn any necessary compilations and copy files to the docs/tutorial/examples/web/bookstore3/build directory. The deploy target copies the bookstore3 context file to <JWSDP_HOME >/webappsas described in Running Web Applications (page 360).

  4. Start the Pointbase database server (see Accessing Databases from Web Applications (page 363)).

  5. Start or restart Tomcat.

  6. Open the bookstore URL http://localhost:8080/bookstore3/enter.

See Common Problems and Their Solutions (page 65) and Troubleshooting (page 369) for help with diagnosing common problems.