Download
FAQ History |
API
Search Feedback |
The Example JSP Document
This chapter uses the Duke's Bookstore and
books
applications to demonstrate how to write JSP pages in XML syntax. The JSP pages of thebookstore5
application use the JSTL XML tags (see XML Tag Library) to manipulate the book data from an XML stream. Thebooks
application contains the JSP documentbooks.jspx
, which accesses the book data from the database and converts it into the XML stream. Thebookstore5
application accesses this XML stream to get the book data.These applications show how easy it is to generate XML data and stream it between Web applications. The
books
application can be considered the application hosted by the book warehouse's server. Thebookstore5
application can be considered the application hosted by the book retailer's server. In this way, the customer of the bookstore Web site sees the list of books currently available, according to the warehouse's database.The source for the Duke's Bookstore application is located in the
<
INSTALL
>/j2eetutorial14/examples/web/bookstore5/
directory, which is created when you unzip the tutorial bundle (see About the Examples). Samplebookstore5.war
andbooks.war
files are provided in<
INSTALL
>/j2eetutorial14/examples/web/provided-wars/
.To build, package, deploy, and run the applications, 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/bookstore5/
.- Run
asant
build
. This target will spawn any necessary compilations and copy files to the<
INSTALL
>/j2eetutorial14/examples/web/bookstore5/build/
directory.- Start the Application Server.
- Perform all the operations described in Accessing Databases from Web Applications.
- Start
deploytool
.- Create a Web application called
bookstore5
by running the New Web Application Wizard. Select FileNewWeb Component.- In the New Web Component wizard:
- In the Introduction screen, click Next.
- In the WAR File screen, select the Create New Stand-Alone WAR Module radio button.
- Click Browse and in the file chooser, navigate to
<
INSTALL
>/j2eetutorial14/examples/web/bookstore5/
.- In the File Name field, enter
bookstore5
.- Click Choose Module File.
- In the WAR Name field, enter
bookstore5
.- In the Context Root field, enter
/bookstore5
.- Click Edit Contents.
- In the Edit Contents dialog box, navigate to
<
INSTALL
>/j2eetutorial14/examples/web/bookstore5/build
/. Select the JSP pagesbookcashier.jsp
,bookcatalog.jsp
,bookdetails.jsp
,bookreceipt.jsp
,bookshowcart.jsp
,bookstore.jsp
, andparsebooks.jsp
along with thetemplate
directory and click Add. Click OK.- Add the shared bookstore library. Navigate to
<
INSTALL
>/j2eetutorial14/examples/build/web/bookstore/dist/
. Selectbookstore.jar
and Click Add.- Click OK.
- Click Next.
- Select the JSP file radio button.
- Click Next.
- Select /
bookstore.jsp
from the JSP Filename combo box.- Click Finish.
- Add each of the Web components listed in Table 13-1. For each component:
- Select FileNewWeb Component.
- Click Next in the Introduction screen.
- In the WAR File screen, click the Add to Existing WAR Module radio button. The WAR file contains all the JSP pages, so you do not have to add any more content.
- Click Next.
- Select the JSP Page radio button.
- Click Next.
- Select the page from the JSP Filename combo box.
- Click Finish.
- From the tree, select the Web component you added.
- Select the Aliases tab.
- Click Add. Enter the alias as shown in Table 13-1.
- Add the context parameter that specifies the JSTL resource bundle basename.
- Add the context parameter that identifies the context path to the XML stream.
- Set the prelude and coda for all JSP pages.
- Select the JSP Properties tab.
- Click the Add button next to the Name list.
- Enter
bookstore5
.- Click the Add URL button next to the URL Pattern list.
- Enter
*.jsp
.- Click the Edit Preludes button next to the Include Preludes list.
- Click Add.
- Enter
/template/prelude.jspf
.- Click OK.
- Click the Edit Codas button next to the Include Codas list.
- Click Add.
- Enter
/template/coda.jspf
.- Click OK.
- Select FileSave.
- Deploy the application.
- Create a Web application called
books
by running the New Web Component wizard. Select FileNewWeb Component.- In the New Web Component wizard:
- In the WAR File screen, select the Create New Stand-Alone WAR Module radio button.
- Click Browse and in the file chooser, navigate to
<
INSTALL
>/j2eetutorial14/examples/web/bookstore5/
.- In the File Name field, enter
books
.- Click Choose Module File.
- In the WAR Display Name field, enter
books
.- In the Context Root field, enter
/books
.- Click Edit Contents.
- In the Edit Contents dialog box, navigate to
<
INSTALL
>/j2eetutorial14/examples/web/bookstore5/build
/. Select the JSP documentbooks.jspx
and thedatabase
,listeners
, andtemplate
directories and click Add.- Add the shared bookstore library. Navigate to
<
INSTALL
>/j2eetutorial14/examples/build/web/bookstore/dist/
. Selectbookstore.jar
and click Add. Click OK.- Click Next.
- Select the JSP Page radio button.
- Click Next.
- Select /
books.jspx
from the JSP Filename combo box.- Click Finish.
- Identify
books.jspx
as an XML document.- Add the listener class
listeners.ContextListener
(described in Handling Servlet Life-Cycle Events).- Add a resource reference for the database.
- Select the Resource Ref's tab.
- Click Add.
- Enter
jdbc/BookDB
in the Coded Name field.- Accept the default type
javax.sql.DataSource
.- Accept the default authorization
Container
.- Accept the default selected
Shareable
.- Enter
jdbc/BookDB
in the JNDI name field of the Sun-specific Settings for jdbc/BookDB frame.- Select FileSave.
- Deploy the application.
- Open the bookstore URL
http://localhost:8080/bookstore5/bookstore
.
Download
FAQ History |
API
Search Feedback |
All of the material in The J2EE(TM) 1.4 Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.