© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
Tutorial 30 – Bookstore Application:
Client Tier
Introducing HTML
Outline
30.1 Analyzing the Bookstore Application 30.2 Creating JavaServer Pages
30.3 Creating the books.jsp Page
30.4 Creating the bookInformation.jsp Page 30.5 Wrap-Up
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
• In this tutorial, you will learn to:
– Create a JSP Web Application.
– Create and design JSP pages.
– Use HTML form controls and other HTML elements.
– Use these technologies to implement the client tier of a three-tier web-based application.
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
30.1 Analyzing the Bookstore Application
When the books.jsp page is requested
Retrieve the book titles from the database Display the book titles in an HTML menu
If the user selects a book title from the menu and clicks the View Information (submit) button Request the bookInformation.jsp page for the selected title
When the bookInformation.jsp page is requested from books.jsp
Retrieve the selected book’s information from a database for the selected title Format the retrieved information in the bookInformation.jsp page
Return the result to the client browser
If the user clicks the Book List link on the bookInformation.jsp page Request the books.jsp page
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
Action Component/Class/Object Event/Method
books.jsp page is requested books.jsp JSP requested by client
Web browser
connect to the database Connection getConnection
create statement Connection createStatement
retrieve the book titles from the database
Statement executeQuery
display them in the select
element ResultSet,
select HTML element, option HTML element
get methods
request the
bookInformation.jsp page input HTML element with type submit
Click the bookInformation.jsp page
is requested bookInformation.jsp JSP requested by client
Web browser
connect to the database Connection getConnection
Figure 30.1 ACE table for the Web-based Bookstore application (Part 1 of 2).
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
(Cont.)
Action Component/Class/Object Event/Method
create statement Connection createStatement
retrieve the selected book’s information from the
database
Statement executeQuery
format the retrieved information in the bookInformation.jsp
ResultSet,
p (paragraph) HTML elements, img HTML element
get methods
User clicks the Book List link on the bookInformation.jsp page to request the books.jsp page
a (anchor) HTML element User clicks the hyperlink
Figure 30.1 ACE table for the Web-based Bookstore application (Part 2 of 2).
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
• JavaServer pages look like HTML
– Include HTML markup and JSP code
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
30.3 Creating the books.jsp Page
• HTML comment
– <!-- comment -->
• HTML markup
– Elements – Start tag – End tag
– title element
– head element
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
Figure 30.2 Adding the title to the JSP.
Setting the JSP’s title
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
30.3 Creating the books.jsp Page (Cont.)
Figure 30.3 Adding a heading to the JSP.
Adding an h1
header element
• body element
• header elements
— h1
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
Figure 30.4 Creating a form in the JSP.
Creating an HTML form
• form element
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
30.3 Creating the books.jsp Page (Cont.)
Figure 30.5 Creating a paragraph text in the JSP.
Creating a paragraph of text
• paragraph tags (<p> and </p>)
• p element
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
Figure 30.6 Creating an empty select statement in the JSP.
Creating an HTML menu control
• select element (HTML menu control)
— name attribute
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
30.3 Creating the books.jsp Page (Cont.)
Figure 30.7 Adding the "submit" button to the JSP.
• input element
— type attribute
— "submit" button
— value attribute
Adding a
"submit" button
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
Figure 30.8 Updated JSP with an HTML form.
Header (h1) element Paragraph (p) element HTML menu control
(select element)
"submit" button (input element of type "submit")
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
Page
Figure 30.9 Adding a title to bookInformation.jsp.
Setting the JSP’s title
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
Figure 30.10 Adding the header that will specify the book title.
Adding an h1
header element
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
Page (Cont.)
Figure 30.11 Adding the img element that will specify the book’s cover.
• img element
— src attribute
— alt attribute
Adding an image to the JSP
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
Figure 30.12 Adding the authors paragraph.
Adding the authors paragraph
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
Page (Cont.)
Figure 30.13 Adding the price paragraph.
Adding the price paragraph
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
Figure 30.14 Adding the ISBN paragraph.
Adding the ISBN paragraph
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
Page (Cont.)
Figure 30.15 Adding the edition paragraph.
Adding the edition paragraph
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
Figure 30.16 Adding the copyright year paragraph.
Adding the copyright year paragraph
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
Page (Cont.)
Figure 30.17 Adding the description paragraph.
Adding the description paragraph
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
Figure 30.18 Adding the Book List hyperlink.
Adding a hyperlink
• Hyperlink
– a (anchor) element
– href (hyperlink reference) attribute
– relative URL
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved.
Page
Figure 30.19 Displaying the bookInformation.jsp and linking to books.jsp.
Result of img
element at line 21
Result of hyperlink at line 42
2004 Prentice Hall, Inc.
All rights reserved.
7 <!-- specify HTML head element -->
8 <head>
9
10 <!-- specify page title -->
11 <title>Book List</title>
12 </head>
13
14 <!-- begin body of document -->
15 <body>
16 <h1>Available Books</h1>
17
Setting the JSP’s title
Adding an h1
header element
2004 Prentice Hall, Inc.
All rights reserved.
books.jsp (2 of 2)
20 21 <p>Select a book from the list and click the button to 22 view the selected book's information</p>
23
24 <!-- create list that contains book titles -->
25 <select name = "bookTitle">
26 27 </select>
28 29 <!-- create View Information button -->
30 <p><input type = "submit" value = "View Information"></p>
31 32 </form>
33 </body>
34 </html>
Adding an HTML form that contains a paragraph, a drop- down list and a
"submit" button
2004 Prentice Hall, Inc.
All rights reserved.
7 <!-- specify head element -->
8 <head>
9
10 <!-- specify page title -->
11 <title>Book Information</title>
12 </head>
13
14 <!-- begin body of document -->
15 <body>
16
17 <!-- create a heading for the book's title -->
18 <h1></h1>
19
20 <!-- display book cover image -->
21 <img src = "" alt = "">
22
23 <!-- display authors -->
24 <p>Authors: </p>
25
Setting the JSP’s title
Adding an h1
header element
Adding authors paragraph
Adding an image
2004 Prentice Hall, Inc.
All rights reserved.
bookInformation.jsp (2 of 2)
28
29 <!-- display ISBN -->
30 <p>ISBN: </p>
31
32 <!-- display edition number -->
33 <p>Edition: </p>
34
35 <!-- display copyright year -->
36 <p>Copyright Year: </p>
37
38 <!-- display authors -->
39 <p>Description: </p>
40
41 <!-- create link to Book List -->
42 <p><a href = "books.jsp">Book List</a></p>
43
44 </body>
45 </html>
Adding price paragraph Adding ISBN paragraph
Adding edition paragraph
Adding copyright year paragraph Adding description paragraph
Adding a hyperlink to books.jsp