The J2EETM Tutorial
Home
TOC
PREV TOC NEXT Search
Feedback

The Example JSP Pages

To illustrate JSP technology, this chapter rewrites each servlet in the Duke's Bookstore application introduced in The Example Servlets as a JSP page:

Table 16 Duke's Bookstore Example JSP Pages 
Function
JSP Page
Enter the bookstore
bookstore.jsp
Create the bookstore banner
banner.jsp
Browse the books offered for sale
catalog.jsp
Put a book in a shopping cart
catalog.jsp and bookdetails.jsp
Get detailed information on a specific book
bookdetails.jsp
Display the shopping cart
showcart.jsp
Remove one or more books from the shopping cart
showcart.jsp
Buy the books in the shopping cart
cashier.jsp
Receive an acknowledgement for the purchase
receipt.jsp

The source for the application is located in examples/src/web/bookstore2. The data for the bookstore application is still maintained in a Cloudscape database. However, two changes are made to the database helper object database.BookDB:

Finally, this version of the example uses an applet to generate a dynamic digital clock in the banner. See Including an Applet for a description of the JSP element that generates HTML for downloading the applet.

To build, deploy, and run the example:

  1. Go to examples/src and build the example by running ant bookstore2.
  2. Start the Cloudscape database by executing cloudscape -start.
  3. If you have not already created the bookstore database, run ant create-web-db.
  4. Start the j2ee server.
  5. Start deploytool.
  6. Create a J2EE application called bookstore2.
    1. Select File->New Application or the New Application button.
    2. Enter bookstore2.ear in the Application File Name field.
    3. Click OK.
  7. Add the bookstore2 WAR to the bookstore2 application.
    1. Select File->Add to Application->Web WAR or the Web WAR button.
    2. In the Add Web WAR dialog, navigate to examples/build/web/bookstore2. Select bookstore2.war. Click Add Web WAR.
  8. Add the BookDBEJB enterprise bean to the application.
    1. Select File->New Enterprise Bean or the New Enterprise Bean button.
    2. Select bookstore2 from Enterprise Bean will Go In combo box.
    3. Type BookDBEJB in the JAR Display Name field.
    4. Click Add to add the content files. Navigate to the examples/build/web/ejb directory and add the database and exception packages. Click Next.
    5. Chose Session and Stateless for the Bean Type.
    6. Select BookDBEJBImpl for Enterprise Bean Class.
    7. Select BookDBEJBHome for Home Interface.
    8. Select BookDBEJB for Remote Interface.
    9. Enter BookDBEJB for Enterprise Bean Name.
    10. Type BookDBEJB in the JNDI Name field next to the BookDB component.
  9. Add a resource reference for the Cloudscape database.
    1. Select the BookDBEJB enterprise bean.
    2. Select the Resource Ref's tab.
    3. Click Add.
    4. Select javax.sql.DataSource from the Type column
    5. Enter jdbc/BookDB in the Coded Name field.
    6. Enter jdbc/Cloudscape in the JNDI Name field.
  10. Add a reference to the enterprise bean BookDBEJB.
    1. Select the bookstore2 WAR.
    2. Select the EJB Ref's tab.
    3. Click Add.
    4. Enter ejb/BookDBEJB in the Coded Name field.
    5. Enter Session in the Type field.
    6. Enter BookDBEJBHome in the Home field.
    7. Enter BookDBEJB in the Remote field.
    8. Enter BookDBEJB in the JNDI Name field.
  11. Deploy the application. Select Tools->Deploy Application or the Deploy Application Button. Click Next twice. Type BookDBEJB in the Application->JNDI Name field and bookstore2 for the context root. Click Next and Finish.
  12. Open the bookstore URL http://<host>:8000/bookstore2/enter.

See Troubleshooting for help with diagnosing common problems.

Home
TOC
PREV TOC NEXT Search
Feedback