|
Home
TOC Index |
|
The Example JSP Pages
This chapter illustrates JSTL with excerpts from the JSP version of the Duke's Bookstore application discussed in Chapter 15 rewritten as follows:
- The Struts logic tags were replaced with JSTL core tags.
- The scriptlets accessing a message store were replaced with message formatting tags.
- The JavaBeans component database helper object was replaced 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
<JWSDP_HOME>/docs/tutorial/examples/web/bookstore4directory created when you unzip the tutorial bundle (see Running the Examples).To build, install, and run the example:
- In a terminal window, go to
<JWSDP_HOME>/docs/tutorial/examples/web/bookstore4.- Run
antbuild. Thebuildtarget will spawn any necessary compilations and copy files to the<JWSDP_HOME>/docs/tutorial/examples/web/bookstore4/builddirectory.- Make sure Tomcat is started.
- Run
antinstall. Theinstalltarget notifies Tomcat that the new context is available.- Start the PointBase database server and populate the database if you have not done so already (see Accessing Databases from Web Applications).
- Open the bookstore URL
http://localhost:8080/bookstore4/enter.To deploy the application using deploytool:
- Make sure Tomcat is started.
- Start
deploytool.- Create a Web application called
bookstore4.
- Select File
New Web Application.
- Click Browse.
- In the file chooser, navigate to
<JWSDP_HOME>/docs/tutorial/examples/web/bookstore4/build.- In the File Name field, enter
bookstore4.- Click Choose Module File.
- In the WAR Display Name field, enter
bookstore4.- Click Edit to add the content files. In the Edit Contents dialog, navigate to
<JWSDP_HOME>/docs/tutorial/examples/web/web/bookstore4/build. Select the JSP pagesbanner.jsp,bookstore.jsp,bookdetails.jsp,catalog.jsp,showcart.jsp,cashier.jsp,receipt.jsp,template.jsp,screendefinitions.jsp, anderrorpage.jsp, andduke.books.gifand click Add. Navigate toWEB-INF. AddDispatcher.classand thecart,database,messages,taglib, andutilpackages fromclassesand the JSTL TLDs and libraries fromlib. Click OK.- Click Next.
- Select the Servlet radio button.
- Click Next.
- Select
Dispatcherfrom the Servlet class combo box.- Click Finish.
- Add the aliases.
- Select
Dispatcher- Select the Aliases tab.
- Click Add and then type
/enterin theAliasesfield. Repeat to add the aliases/catalog,/bookdetails,/showcart,/cashier, and/receipt.- Add the JSTL basename context parameter.
- Select the Context tab.
- Click Add.
- Enter javax.servlet.jsp.jstl.fmt.localizationContext for the Coded Parameter.
- Enter messages.BookstoreMessages for the Value.
- Add a resource reference for the database.
- Select the
WAR.- Select the Resource Refs tab.
- Click Add.
- Select
javax.sql.DataSourcefrom the Type column- Enter
jdbc/BookDBin the Coded Name field.- Click the Import Data Sources button.
- Dismiss the confirmation dialog.
- Select
pointbasefrom the drop down list.- Add the tag library URI to location mappings (see Declaring Tag Libraries):
- Select the File Refs tab.
- Click the Add button in the JSP Tag Libraries tab.
- Enter the relative URI
/tutorial-templatein the Coded Reference field.- Enter the absolute location
/WEB-INF/tutorial-template.tldin the Tag Library field.- Repeat for
/jstl-cto/WEB-INF/c.tld,/jstl-fmtto/WEB-INF/fmt.tld, and/jstl-sqlto/WEB-INF/sql.tld.- Deploy the application.
See Common Problems and Their Solutions and Troubleshooting for help with diagnosing common problems.
|
Home
TOC Index |
|
This tutorial contains information on the 1.0 version of the Java Web Services Developer Pack.
All of the material in The Java Web Services Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.