The Example JSP Pages
This chapter illustrates JSTL using excerpts from the JSP version of the Duke's Bookstore application discussed in Chapter 12. Here, they are rewritten to replace the JavaBeans component database access object with direct calls to the database via the JSTL SQL tags. For most applications, it is better to encapsulate calls to a database in a bean. JSTL includes SQL tags for situations where a new application is being prototyped and the overhead of creating a bean may not be warranted.
The source for the Duke's Bookstore application is located in the
<
INSTALL
>/j2eetutorial14/examples/web/bookstore4/
directory created when you unzip the tutorial bundle (see About the Examples). A samplebookstore4.war
is provided in<
INSTALL
>/j2eetutorial14/examples/web/provided-wars/
. To build the example, follow these steps:
- Build and package the bookstore common files as described in Duke's Bookstore Examples.
- In a terminal window, go to
<
INSTALL
>/j2eetutorial14/examples/web/bookstore4/
.- Run
asant
build
. This target will copy files to the<
INSTALL
>/j2eetutorial14/examples/web/bookstore4/build/
directory.- Start the Application Server.
- Perform all the operations described in Accessing Databases from Web Applications.
To package and deploy the example using
asant
, follow these steps:To learn how to configure the example, use
deploytool
to package and deploy it:
- Start
deploytool
.- Create a web application called
bookstore4
by running the New Web Component wizard. Select FileNewWeb Component.- In the New Web Component wizard:
- Select the Create New Stand-Alone WAR Module radio button.
- In the WAR File field, enter
<
INSTALL
>/j2eetutorial14/examples/web/bookstore4/bookstore4.war
. The WAR Display Name field will showbookstore4
.- In the Context Root field, enter
/bookstore4
.- Click Edit Contents.
- In the Edit Contents dialog box, navigate to
<
INSTALL
>/j2eetutorial14/examples/web/bookstore4/build
/. Select the JSP pagesbookstore.jsp
,bookdetails.jsp
,bookcatalog.jsp
,bookshowcart.jsp
,bookcashier.jsp
, andbookreceipt.jsp
and thetemplate
directory and click Add.- Add the shared bookstore library. Navigate to
<
INSTALL
>/j2eetutorial14/examples/web/bookstore/dist/
. Selectbookstore.jar
and click Add.- Click OK.
- Click Next.
- Select the JSP Page radio button.
- Click Next.
- Select /
bookstore.jsp
from the JSP Filename combo box.- Click Finish.
- Add the alias for the bookstore.jsp component:
- Add each of the web components listed in Table 14-1. For each component:
- Set the alias for each web component.
- Add the context parameter that specifies the JSTL resource bundle base name.
- Set the prelude and coda for all JSP pages.
- Add a resource reference for the database.
- Select FileSave.
- Deploy the application.
To run the application, open the bookstore URL
http://localhost:8080/bookstore4/bookstore
.See Troubleshooting for help with diagnosing common problems.