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.

}<br />

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

this.database = database;<br />

}<br />

public Book getBook() throws<br />

BookNotFoundException {<br />

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

}<br />

public List getBooks() throws BooksNotFoundException {<br />

return database.getBooks();<br />

}<br />

public void buyBooks(ShoppingCart cart)<br />

throws OrderException {<br />

database.buyBooks(cart);<br />

}<br />

public int getNumberOfBooks() throws BooksNotFoundException {<br />

return database.getNumberOfBooks();<br />

}<br />

Creating and Using a <strong>Java</strong>Beans Component<br />

To declare that your JSP page will use a <strong>Java</strong>Beans component, you use a jsp:useBean element.<br />

<strong>The</strong>re are two forms:<br />

<br />

and<br />

<br />

<br />

<br />

<strong>Java</strong>Beans Components<br />

<strong>The</strong> second form is used when you want to include jsp:setProperty statements, described in<br />

the next section, for initializing bean properties.<br />

<strong>The</strong> jsp:useBean element declares that the page will use a bean that is stored within and is<br />

accessible from the specified scope, which can be application, session, request,orpage.If<br />

no such bean exists, the statement creates the bean and stores it as an attribute of the scope<br />

object (see “Using Scope Objects” on page 105). <strong>The</strong> value of the id attribute determines the<br />

name of the bean in the scope and the identifier used to reference the bean in EL expressions,<br />

other JSP elements, and scripting expressions (see Chapter 9, “Scripting in JSP Pages”). <strong>The</strong><br />

value supplied for the class attribute must be a fully qualified class name. Note that beans<br />

cannot be in the unnamed package. Thus the format of the value must be<br />

package-name.class-name.<br />

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

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

Saved successfully!

Ooh no, something went wrong!