2. Using the Tutorial Examples 3. Getting Started with Web Applications 5. JavaServer Pages Technology Using Objects within JSP Pages Using Application-Specific Objects Immediate and Deferred Evaluation Syntax Deactivating Expression Evaluation Process of Expression Evaluation JavaBeans Component Design Conventions Creating and Using a JavaBeans Component Setting JavaBeans Component Properties Retrieving JavaBeans Component Properties Including the Tag Library Implementation Transferring Control to Another Web Component Setting Properties for Groups of JSP Pages Deactivating EL Expression Evaluation Further Information about JavaServer Pages Technology 7. JavaServer Pages Standard Tag Library 10. JavaServer Faces Technology 11. Using JavaServer Faces Technology in JSP Pages 12. Developing with JavaServer Faces Technology 13. Creating Custom UI Components 14. Configuring JavaServer Faces Applications 15. Internationalizing and Localizing Web Applications 16. Building Web Services with JAX-WS 17. Binding between XML Schema and Java Classes 19. SOAP with Attachments API for Java 21. Getting Started with Enterprise Beans 23. A Message-Driven Bean Example 24. Introduction to the Java Persistence API 25. Persistence in the Web Tier 26. Persistence in the EJB Tier 27. The Java Persistence Query Language 28. Introduction to Security in the Java EE Platform 29. Securing Java EE Applications 31. The Java Message Service API 32. Java EE Examples Using the JMS API 36. The Coffee Break Application | The Example JSP PagesTo illustrate JSP technology, this chapter rewrites each servlet in the Duke’s Bookstoreapplication introduced inThe Example Servlets as a JSP page (seeTable 5-1). Table 5-1 Duke’s Bookstore Example JSP Pages
The data for the bookstore application is still maintained in a database andis accessed throughtut-install/javaeetutorial5/examples/web/bookstore2/src/java/com/sun/bookstore2/database/BookDBAO.java. However, the JSP pages accessBookDBAO through the JavaBeanscomponenttut-install/javaeetutorial5/examples/web/bookstore2/src/java/com/sun/bookstore2/database/BookDB.java. This class allows the JSP pages to use JSP elementsdesigned to work with JavaBeans components (seeJavaBeans Component Design Conventions). The implementation of the database bean follows. The bean has two instance variables:the current book and the data access object. package database;public class BookDB { private String bookId = "0"; private BookDBAO database = null; public BookDB () throws Exception { } public void setBookId(String bookId) { this.bookId = bookId; } public void setDatabase(BookDAO database) { this.database = database; } public Book getBook() throws Exception { return (Book)database.getBook(bookId); } ...}This version of the Duke’s Bookstore application is organized along the Model-View-Controller (MVC)architecture. The MVC architecture is a widely used architectural approach for interactive applicationsthat distributes functionality among application objects so as to minimize the degree ofcoupling between the objects. To achieve this, it divides applications into three layers: model,view, and controller. Each layer handles specific tasks and has responsibilities to theother layers:
Note -When employed in a web application, the MVC architecture is often referred toas a Model-2 architecture. The bookstore example discussed inChapter 4, Java Servlet Technology, which intermixes presentationand business logic, follows what is known as a Model-1 architecture. The Model-2architecture is the recommended approach to designing web applications. In addition, this version of the application uses several custom tags from theJavaServer Pages Standard Tag Library (JSTL), described inChapter 7, JavaServer Pages Standard Tag Library:
Custom tags are the preferred mechanism for performing a wide variety of dynamicprocessing tasks, including accessing databases, using enterprise services such as email and directories,and implementing flow control. In earlier versions of JSP technology, such tasks wereperformed with JavaBeans components in conjunction with scripting elements (discussed inChapter 9, Scripting in JSP Pages). Although stillavailable in JSP 2.0 technology, scripting elements tend to make JSP pages moredifficult to maintain because they mix presentation and logic, something that is discouragedin page design. Custom tags are introduced inUsing Custom Tags and described indetail inChapter 8, Custom Tags in JSP Pages. Finally, this version of the example contains an applet to generate a dynamicdigital clock in the banner. SeeIncluding an Applet for a description of theJSP element that generates HTML for downloading the applet. To deploy and run the application using NetBeans IDE, follow these steps:
To deploy and run the application using Ant, follow these steps:
To learn how to configure the example, refer to the deployment descriptor (theweb.xml file), which includes the following configurations:
Figure 5-2 shows thebookcatalog.jsp page from the Duke’s Bookstore application. This page displaysa list of all the books that are available for purchase. Figure 5-2 Book Catalog ![]() SeeTroubleshooting Duke's Bookstore Database Problems for help with diagnosing common problems related to the database server.If the messages in your pages appear as strings of the form???Key???, the likely cause is that you have not provided thecorrect resource bundle base name as a context parameter. Copyright © 2010, Oracle and/or its affiliates. All rights reserved.Legal Notices |