© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 32.1 Reviewing the Bookstore Application 32.2.

Slides:



Advertisements
Similar presentations
 2003 Prentice Hall, Inc. All rights reserved. Chapter 24: Servlets Outline 24.1 Introduction 24.2 Servlet Overview and Architecture Interface.
Advertisements

Chapter 25: JavaServer Pages Outline 25.1 Introduction 25.2 JavaServer Pages Overview 25.3 First JavaServer Page Example 25.4 Implicit Objects 25.5 Scripting.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Introduction to SQL Programming Techniques.
Excel and VBA Creating an Excel Application
 2008 Pearson Education, Inc. All rights reserved. 1 Introduction to HTML.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 5 - Introduction to XHTML: Part 2 Outline 5.1 Introduction 5.2 Basic XHTML Tables 5.3 Intermediate.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 37 - JavaServer Pages (JSP): Bonus for Java Developers Outline 37.1 Introduction 37.2 JavaServer.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 35 – Python Outline 35.1 Introduction First Python Program Python Keywords 35.2 Basic.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Bookstore Web Application Introducing Visual Web Developer 2008 Express and the.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 29.1 Multi-Tier Architecture 29.2 Web Servers.
CSCI 6962: Server-side Design and Programming JDBC Database Programming.
1 Outline 3.1 Introduction 3.2 Editing HTML 3.3 First HTML Example 3.4 W3C HTML Validation Service 3.5 Headers 3.6 Linking 3.7 Images 3.8 Special Characters.
Server-side Scripting Powering the webs favourite services.
Jaeki Song JAVA Lecture 11 Java Database Connectivity.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Introducing Web Controls Outline 29.1 Analyzing the.
CIS 270—Application Development II Chapter 25—Accessing Databases with JDBC.
1 XHTML Forms A form is the mechanism to –Collect information from a browser user –Transmit collected information from a browser to a server HTML/XHTML.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Exploring Microsoft Office Word 2007 Chapter 8 Word and the Internet Robert Grauer, Keith.
Project Implementation for COSC 5050 Distributed Database Applications Lab3.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 30 – Bookstore Application: Client Tier Introducing.
Java Servlets and Java Server Pages Carol Wolf Computer Science.
 2002 Prentice Hall, Inc. All rights reserved.2 Chapter 2 — Introduction to HyperText Markup Language 4: Part I Outline 2.1Introduction 2.2Markup Languages.
Active Server Pages ASP is Microsoft’s server-side script engine for dynamically-generated web pages. Most common language used is VBScript. If you use.
Java Server Pages A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format,
 2004 Prentice Hall, Inc. All rights reserved. Chapter 5 - Introduction to XHTML: Part 2 Outline 5.1 Introduction 5.2 Basic XHTML Tables 5.3 Intermediate.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 38 Advanced Java Database.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 30 – Bookstore Application: Client Tier Examining.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 27 - Phone Book Application Introducing Multimedia.
Java Servlets Outline 24.1 Introduction 24.2 Servlet Overview and Architecture Interface Servlet and the Servlet Life Cycle HttpServlet Class.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
Mark Dixon 1 09 – Java Servlets. Mark Dixon 2 Session Aims & Objectives Aims –To cover a range of web-application design techniques Objectives, by end.
ITCS373: Internet Technology Lecture 5: More HTML.
 2003 Prentice Hall, Inc. All rights reserved. Introduction to HTML: Frames Outline 1 Introduction 2 frameset Element 3 Nested frameset s 4 Web Resources.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 33 Advanced Java.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 17 – Flag Quiz Application Introducing One-Dimensional.
JSP program that interacts with HTML form & Access Data Base.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 16 - Dynamic HTML: Data Binding with Tabular Data Control Outline 16.1 Introduction 16.2 Simple.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 31.1 Reviewing the Bookstore Application 31.2.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Shipping Hub Application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 2.1 Test-Driving the Welcome Application 2.2.
INSERT BOOK COVER 1Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Getting Started with VBA for Microsoft Office 2010 by.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Bookstore Application: Middle Tier Introducing Code-Behind Files, Session State.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 18 – Student Grades Application Introducing.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 8.1 Test-Driving the Car Payment Calculator.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
 2002 Prentice Hall. All rights reserved. 9.8 Multi-Tier Applications: Using JDBC from a Servlet Three-tier distributed applications –User interface –Business.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 24: Servlets Outline 24.1 Introduction 24.2 Servlet Overview and Architecture Interface.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 24.1 Test-Driving the Enhanced Car Payment.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Vakgroep Informatietechnologie – Onderzoeksgroep (naam) Web Centric Design of Distributed Software.
Web Authoring with Dreamweaver. Unit Objectives  Be able to define keywords: HTML, HTTP (protocol), browser, web server, client/server, tag, attribute,
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
Internet & World Wide Web How to Program, 5/e Copyright © Pearson, Inc All Rights Reserved.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
Database Processing with JSP ISYS 350. Database Applications Applications Database Server Queries/Updates Results.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 7.1 Test-Driving the Dental Payment Application.
CS320 Web and Internet Programming Database Access with JDBC Chengyu Sun California State University, Los Angeles.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 22 - i-mode Outline 22.1 Introduction 22.2 Japan’s Telecommunications Industry and Infrastructure.
Computing with C# and the .NET Framework
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
Section 17.1 Section 17.2 Add an audio file using HTML
IS333: MULTI-TIER APPLICATION DEVELOPMENT
Presentation transcript:

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 32.1 Reviewing the Bookstore Application 32.2 Adding Functionality to the books.jsp Page 32.3 Adding Functionality to the bookInformation.jsp Page 32.4 Internet and Web Resources 32.5 Wrap-Up Tutorial 32 – Bookstore Application: Middle Tier form Attributes method/action and Inserting Query Results in a JSP

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 2 Objectives In this tutorial, you will learn to: –Write the functionality for the middle tier, using JSP. –Process a ResultSet inside a JSP scriptlet. –Use JSP expressions to insert content in a JSP.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Reviewing 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 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Reviewing the Bookstore Application (Cont.)

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Reviewing the Bookstore Application (Cont.)

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Adding Functionality to the books.jsp Page Figure 32.2 while statement that gets book titles from the ResultSet. while statement that iterates through the ResultSet and gets each book title

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Adding Functionality to the books.jsp Page (Cont.) Figure 32.3 Displaying the current book title. Adding book titles to HTML menu control option element Adds items to the menu control JSP expression add dynamic content (information from a database)

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Adding Functionality to the books.jsp Page (Cont.) Figure 32.4 Closing the result set. Closing the ResultSet

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Adding Functionality to the books.jsp Page (Cont.) Figure 32.5 Running the updated books.jsp. HTML menu control was filled with book titles by using the HTML option element

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Adding Functionality to the books.jsp Page (Cont.) Figure 32.6 Adding action to the form element. Specifying form action form element –method attribute Specifies how data is sent to the Web server –action attribute Specifies task to perform when user submits the form

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Adding Functionality to the books.jsp Page (Cont.) Figure 32.7 Running the updated books.jsp page. Clicking this button forwards the user’s request to bookInformation.jsp

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Adding Functionality to the bookInformation.jsp Page Figure 32.8 Displaying the book title. Displaying book title in an h1 header Figure 32.9 Accessing the ResultSet results. Calling method next for the first time positions the ResultSet cursor in the first row of the ResultSet

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Adding Functionality to the bookInformation.jsp Page (Cont.) Figure Displaying book cover image. Figure Displaying the authors. Display the book cover image Display the book authors

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Adding Functionality to the bookInformation.jsp Page (Cont.) Figure Displaying the price. Figure Displaying the ISBN. Displaying the book priceDisplaying the book ISBN

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Adding Functionality to the bookInformation.jsp Page (Cont.) Figure Displaying the edition. Figure Displaying the copyright year. Displaying the book edition Display the book copyright year

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Adding Functionality to the bookInformation.jsp Page (Cont.) Figure Displaying the description. Figure Closing the ResultSet. Display the book description Closing the ResultSet

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Adding Functionality to the bookInformation.jsp Page (Cont.) Figure bookInformation.jsp page displaying book information. (Book image courtesy of Prentice Hall.)

 2004 Prentice Hall, Inc. All rights reserved. Outline Book List Available Books Select a book from the list and click the button to view 25 the selected book's information books.jsp (1 of 4) Specifying the form ’s action

 2004 Prentice Hall, Inc. All rights reserved. Outline <% 32 // setup database connection 33 try 34 { 35 // specify database location 36 System.setProperty( "db2j.system.home", 37 "C:\\Examples\\Tutorial29\\Databases" ); // load Cloudscape driver 40 Class.forName( "com.ibm.db2j.jdbc.DB2jDriver" ); // connect to database 43 Connection connection = 44 DriverManager.getConnection( 45 "jdbc:db2j:bookstore" ); 46 books.jsp (2 of 4)

 2004 Prentice Hall, Inc. All rights reserved. Outline // obtain list of titles 48 if ( connection != null ) 49 { 50 Statement statement = 51 connection.createStatement(); ResultSet results = statement.executeQuery( 54 "SELECT title FROM Products" ); // display book title 57 while ( results.next() ) 58 { 59 String currentTitle = 60 results.getString( "title" ); %> <% // continue scriptlet } // end while loop 70 books.jsp (3 of 4) Retrieving the book title from the ResultSet Adding the book title to the HTML menu control

 2004 Prentice Hall, Inc. All rights reserved. Outline results.close(); // close result set // close database connection 74 connection.close(); } // end if } // end try // catch SQLException 81 catch( SQLException exception ) 82 { 83 out.println( 84 "Exception: " + exception + " occurred." ); 85 } %> books.jsp (4 of 4) Closing the ResutSet results

 2004 Prentice Hall, Inc. All rights reserved. Outline Book Information bookInformation.jsp (1 of 5) Displaying the book title specified in books.jsp in an h1 header

 2004 Prentice Hall, Inc. All rights reserved. Outline <% 25 // setup database connection 26 try 27 { 28 // specify database location 29 System.setProperty( "db2j.system.home", 30 "C:\\Examples\\Tutorial29\\Databases" ); // load Cloudscape driver 33 Class.forName( "com.ibm.db2j.jdbc.DB2jDriver" ); // obtain connection to database 36 Connection connection = DriverManager.getConnection( 37 "jdbc:db2j:bookstore" ); // obtain list of titles from database 40 if ( connection != null ) 41 { 42 // create statement 43 Statement statement = connection.createStatement(); 44 bookInformation.jsp (2 of 5)

 2004 Prentice Hall, Inc. All rights reserved. Outline // execute query to get book information 46 ResultSet results = statement.executeQuery( 47 "SELECT cover, title, authors, price, isbn, " + 48 "edition, copyrightYear, description " + 49 "FROM Products WHERE title = '" + 50 request.getParameter( "title" ) + "'" ); results.next(); // move cursor to the first row %> <img src = "images/<%= results.getString( 58 "cover" ) %>" alt = "Book cover for 59."> Author(s): <%= results.getString( 63 "authors" ) %> Price: ISBN: 70 bookInformation.jsp (3 of 5) Moving to the first row of the ResultSet Displaying the authorsDisplaying the priceDisplaying the ISBN

 2004 Prentice Hall, Inc. All rights reserved. Outline Edition: Copyright Year: <%= results.getString( 76 "copyrightYear" ) %> Description: <%= results.getString( 80 "description" ) %> Book List <% // continue scriptlet results.close(); // close result set 88 connection.close(); // close database connection } // end if } // end try 93 bookInformation.jsp (4 of 5) Displaying the edition number Displaying the copyright year Displaying the description Closing the ResutSet

 2004 Prentice Hall, Inc. All rights reserved. Outline // catch SQLException 95 catch( SQLException exception ) 96 { 97 out.println( "Exception: " + exception + " occurred." ); 98 } %> bookInformation.jsp (5 of 5)

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Internet and Web Resources java.sun.com/products/jsp/ java.sun.com/products/jsp/docs.html