10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

TABLE 5–1 Duke’s Bookstore Example JSP Pages (Continued)<br />

Function JSP Pages<br />

Browse the books offered for sale. bookcatalog.jsp<br />

Add a book to the shopping cart. bookcatalog.jsp and bookdetails.jsp<br />

Get detailed information on a specific book. bookdetails.jsp<br />

Display the shopping cart. bookshowcart.jsp<br />

Remove one or more books from the shopping cart. bookshowcart.jsp<br />

Buy the books in the shopping cart. bookcashier.jsp<br />

Receive an acknowledgment for the purchase. bookreceipt.jsp<br />

<strong>The</strong> data for the bookstore application is still maintained in a database and is accessed through<br />

tut-install/javaeetutorial5/examples/web/bookstore2/src/java/com/sun/bookstore2/database<br />

However, the JSP pages access BookDBAO through the <strong>Java</strong>Beans component<br />

tut-install/javaeetutorial5/examples/web/bookstore2/src/java/com/sun/bookstore2/database<br />

This class allows the JSP pages to use JSP elements designed to work with <strong>Java</strong>Beans<br />

components (see “<strong>Java</strong>Beans Component Design Conventions” on page 166).<br />

<strong>The</strong> implementation of the database bean follows. <strong>The</strong> bean has two instance variables: the<br />

current book and the data access object.<br />

package database;<br />

public class BookDB {<br />

private String bookId = "0";<br />

private BookDBAO database = null;<br />

}<br />

public BookDB () throws Exception {<br />

}<br />

public void setBookId(String bookId) {<br />

this.bookId = bookId;<br />

}<br />

public void setDatabase(BookDAO database) {<br />

this.database = database;<br />

}<br />

public Book getBook()<br />

throws Exception {<br />

return (Book)database.getBook(bookId);<br />

}<br />

...<br />

<strong>The</strong> Example JSP Pages<br />

Chapter 5 • <strong>Java</strong>Server PagesTechnology 137

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!