|
Home TOC Index |
|
Search
Feedback |
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 Chapter 11 rewritten to take advantage of two tag libraries: Struts and tutorial-template. The section in this chapter entitled Examples, describes some tags in detail: the
iteratetag 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
The Duke's Bookstore application uses tags from the Struts
beanandlogicsublibraries.The tutorial-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, andparameter--that are used to build a table of screen definitions for Duke's Bookstore and with aninserttag to insert parameters from the table into the screen.Figure 13-1 shows the flow of a request through the following Duke's Bookstore Web components:
template.jsp, which determines the structure of each screen. It uses theinserttag 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 Table 11-1).Dispatcher, a servlet, which processes requests and forwards totemplate.jsp.Figure 13-1 Request Flow through Duke's Bookstore Components
The source for the Duke's Bookstore application is located in the
j2eetutorial/examples/src/web/bookstore3directory created when you unzip the tutorial bundle (see Downloading the Examples). To build, deploy, and run the example:
- Go to
j2eetutorial/examplesand build the application by executingant bookstore3(see How to Build and Run the Examples).- Download and unpack Struts version 1.0 from
http://jakarta.apache.org/builds/jakarta-struts/release/v1.0/
- Copy
struts-bean.tld,struts-logic.tld, andstruts.jarfromjakarta-struts-1.0/libtoexamples/build/web/bookstore3- Start the
j2eeserver.- Start
deploytool.- Start the Cloudscape database by executing
cloudscape -start.- If you have not already created the bookstore database, run
ant create-web-db.- Create a J2EE application called
Bookstore3App.
- Select File
New Application.
- In the file chooser, navigate to
j2eetutorial/examples/src/web/bookstore3.- In the File Name field, enter
Bookstore3App.- Click New Application.
- Click OK.
- Create the WAR and add the
DispatcherServletWeb component and all of the Duke's Bookstore content toBookstore3App.
- Select File
New
Web Component.
- Click the Create New WAR File in Application radio button and select
Bookstore3Appfrom the combo box. EnterBookstore3WARin the field labeled WAR Display Name.- Click Edit to add the content files. In the Edit Contents dialog box, navigate to
j2eetutorial/examples/build/web/bookstore3. Select Dispatcher.class and click Add. Add the JSP pagesbanner.jsp,bookstore.jsp,bookdetails.jsp,catalog.jsp,showcart.jsp,cashier.jsp,receipt.jsp,initdestroy.jsp,template.jsp,screendefinitions.jsp, anderrorpage.jsp. Addduke.books.gif,struts-bean.tld,struts-logic.tld,tutorial-template.tld, andstruts.jar. Add thecart,database,messages,taglib, andutilpackages. Click OK.- Click Next.
- Select the Servlet radio button.
- Click Next.
- Select
Dispatcherfrom the Servlet Class combo box.- Click Next twice.
- In the Component Aliases pane, click Add and then type
/enterin the Alias field. Repeat to add the aliases/catalog,/bookdetails,/showcart,/cashier, and/receipt.- Click Finish.
- Add the
BookDBEJBenterprise bean that you created in the section The Example JSP Pages.
- Select File
Add
EJB JAR.
- Navigate to the directory
examples/build/web/ejb.- Select
bookDB.jar.- Click Add EJB JAR.
- Add a reference to the enterprise bean
BookDBEJB.
- Select
Bookstore3WAR.- Select the EJB Refs tab.
- Click Add.
- Enter
ejb/BookDBEJBin the Coded Name column.- Enter Session in the Type column.
- Select Remote in the Interfaces column.
- Enter
database.BookDBEJBHomein the Home Interface column.- Enter
database.BookDBEJBin the Local/Remote Interface column.- 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 subpane.
- 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
/struts-beanto/WEB-INF/struts-bean.tldand/struts-logicto/WEB-INF/struts-logic.tld.- Specify the JNDI names.
- Select
Bookstore3App.- In the Application table, locate the EJB component and enter
BookDBEJBin the JNDI Name column.- In the References table, locate the EJB Ref and enter
BookDBEJBin the JNDI Name column.- In the References table, locate the Resource component and enter
jdbc/Cloudscapein the JNDI Name column.- Enter the context root.
- Deploy the application.
- Open the bookstore URL
http://<host>:8000/bookstore3/enter.See Troubleshooting for help with diagnosing common problems.
|
Home TOC Index |
|
Search
Feedback |