 2005 Pearson Education, Inc. All rights reserved. 1 27 JavaServer Pages (JSP)

Slides:



Advertisements
Similar presentations
8 Copyright © 2005, Oracle. All rights reserved. Creating the Web Tier: JavaServer Pages.
Advertisements

Java Server Pages Jeffrey Jongko. Introduction Java Server Pages (JSP) technology was created by Sun Microsystems and is built on top of Sun’s Java Servlet.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
Michael Brockway Application Integration JavaServer Pages l Introduction & Overview l Implicit Objects l Scripting l Standard Actions l Directives l References.
Chapter 51 Scripting With JSP Elements JavaServer Pages By Xue Bai.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Using JavaServer Pages Harry R. Erwin, PhD CIT304/CSE301.
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.
 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
JSP: JavaServer Pages Juan Cruz Kevin Hessels Ian Moon.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
JSP Architecture  JSP is a simple text file consisting of HTML or XML content along with JSP elements  JSP packages define the interface for the compiled.
Introduction to scripting
 2004 Prentice Hall, Inc. All rights reserved. Chapter 37 - JavaServer Pages (JSP): Bonus for Java Developers Outline 37.1 Introduction 37.2 JavaServer.
Overview of JSP Technology. The need of JSP With servlets, it is easy to – Read form data – Read HTTP request headers – Set HTTP status codes and response.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
11. Java-Based Web: JSP, JSF. 2 Motto: Rule 1: Our client is always right Rule 2: If you think our client is wrong, see Rule 1. - Anonymous.
 2002 Prentice Hall. All rights reserved. JavaServer Pages.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 9 JavaServer Pages (JSP) (Based on Møller.
Java Server Pages CS-422. What are JSPs A logical evolution of java servlets –most servlets dynamically create HTML and integrate it with some computational.
Netbeans – jsp.zip Introduction to JSP Netbeans – jsp.zip.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
 2005 Pearson Education, Inc. All rights reserved Servlets.
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 25: JavaServer Pages Outline 25.1 Introduction 25.2 JavaServer Pages Overview 25.3 First JavaServer.
Chapter 7 Java Server Pages. Objectives Explain how the separation of concerns principle applies to JSP Describe the operation and life-cycle of a JSP.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
Java Server Pages Lecture July Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java)
Chapter 8 Script-free pages. Problem with scripting in JSP When you use scripting (declaration, scriplet, expressions) in your JSP, you actually put Java.
 2008 Pearson Education, Inc. All rights reserved Introduction to XHTML.
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
JAVA SERVER PAGES CREATING DYNAMIC WEB PAGES USING JAVA James Faeldon CS 119 Enterprise Systems Programming.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 5 – Dental Payment Application: Introducing.
intro JSP Pertemuan 8 Matakuliah: Web Programming Tahun: 2009.
JSP Fundamentals Elements of a JSP Using Beans with JSP Integrating Servlets and JSP.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 27 JavaServer Page.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
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 © 2002 ProsoftTraining. All rights reserved. JavaServer Pages.
 2008 Pearson Education, Inc. All rights reserved PHP.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
CSC 2720 Building Web Applications JavaServer Pages (JSP) JSP Directives and Action Elements.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Basic JSP Celsina Bignoli Problems with Servlets Servlets contain –request processing, –business logic –response generation all lumped.
COMP9321 Web Application Engineering Semester 2, 2015 Dr. Amin Beheshti Service Oriented Computing Group, CSE, UNSW Australia Week 3 1COMP9321, 15s2, Week.
STRUCTURE OF JSP PRESENTED BY: SIDDHARTHA SINGH ( ) SOMYA SHRIVASTAV ( ) SONAM JINDAL ( )
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 43 JavaServer Page.
CSI 3125, Preliminaries, page 1 JSP (Java Server Pages)
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Chapter 6 Chapter 6 Server Side Programming (JSP) Part 1 1 (IS 203) WebProgramming (IS 203) Web Programming.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Java Server Pages. 2 Servlets The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Chapter 14 Using JavaBeans Components in JSP Documents.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Chapter 6 JavaScript: Introduction to Scripting
Introduction to Classes and Objects
Introduction to Scripting
Knowledge Byte In this section, you will learn about:
JavaServer Pages (JSP)
MSIS 655 Advanced Business Applications Programming
COP 4610L: Applications in the Enterprise Spring 2005
Presentation transcript:

 2005 Pearson Education, Inc. All rights reserved JavaServer Pages (JSP)

 2005 Pearson Education, Inc. All rights reserved. 2 If it’s a good script, I’ll do it and if it’s a bad script and they pay me enough, I’ll do it. — George Burns A fair request should be followed by the deed in silence. — Dante Alighieri Talent is a question of quantity. Talent does not write one page: it writes three hundred. — Jules Renard Every action must be due to one or other of seven causes: chance, nature, compulsion, habit, reasoning, anger, or appetite. — Aristotle

 2005 Pearson Education, Inc. All rights reserved. 3 OBJECTIVES In this chapter you will learn:  The differences between servlets and JSPs.  To create and deploy JavaServer Pages.  To use JSP’s implicit objects and scriptlets to create dynamic Web pages.  To specify global JSP information with directives.  To use actions to manipulate JavaBeans in a JSP, to include resources dynamically and to forward requests to other JSPs.

 2005 Pearson Education, Inc. All rights reserved Introduction 27.2 JavaServer Pages Overview 27.3 First JSP Example 27.4 Implicit Objects 27.5 Scripting Scripting Components Scripting Example 27.6 Standard Actions Action Action Action 27.7 Directives page Directive include Directive 27.8 Case Study: Guest Book 27.9 Wrap-Up Internet and Web Resources

 2005 Pearson Education, Inc. All rights reserved Introduction JavaServer Pages – Extension of Servlet technology – Separate the presentation from the business logic – Simplify the delivery of dynamic Web content – Reuse existing Java components JavaBean Custom-tag libraries – Encapsulate complex functionality Classes and interfaces specific to JSP – Package javax.servlet.jsp – Package javax.servlet.jsp.tagext

 2005 Pearson Education, Inc. All rights reserved JavaServer Pages Overview Key components – Directives – Actions – Scripting elements – Tag libraries

 2005 Pearson Education, Inc. All rights reserved JavaServer Pages Overview (Cont.) Directive – Message to JSP container i.e., program that compiles/executes JSPs – Enable programmers to specify Page settings Content to include from other resources Custom tag libraries used in the JSP

 2005 Pearson Education, Inc. All rights reserved JavaServer Pages Overview (Cont.) Action – Predefined JSP tags that encapsulate functionality – Often performed based on information from client request – Can be used to create Java objects for use in scriptlets

 2005 Pearson Education, Inc. All rights reserved JavaServer Pages Overview (Cont.) Scripting elements – Enable programmers to insert Java code in JSPs – Performs request processing Interacts with page elements and other components to implement dynamic pages – Scriptlets One kind of scripting element Contain code fragments – Describe the action to be performed in response to user request

 2005 Pearson Education, Inc. All rights reserved JavaServer Pages Overview (Cont.) Custom Tag Library – JSP’s tag extension mechanism – Enables programmers to define new tags Tags encapsulate complex functionality – Tags can manipulate JSP content

 2005 Pearson Education, Inc. All rights reserved JavaServer Pages Overview (Cont.) JSPs – Look like standard XHTML or XML Normally include XHTML or XML markup – Known as fixed-template data – Used when content is mostly fixed-template data Small amounts of content generated dynamically Servlets – Used when small amount of content is fixed-template data Most content generated dynamically

 2005 Pearson Education, Inc. All rights reserved. 12 Software Engineering Observation 27.1 Literal text in a JSP becomes string literals in the servlet that represents the translated JSP.

 2005 Pearson Education, Inc. All rights reserved JavaServer Pages Overview (Cont.) When server receive the first JSP request – JSP container translates a JSP into a servlet Handle the current and future requests Code that represents the JSP – Placed in servlet’s _jspService method JSP errors – Translation-time errors Occur when JSPs are translated into servlets – Request-time errors Occur during request processing Methods jspInit and jspDestroy – Container invokes them when initializing and terminating a JSP – Defined in JSP declarations

 2005 Pearson Education, Inc. All rights reserved. 14 Performance Tip 27.1 Some JSP containers translate JSPs to servlets at installation time. This eliminates the translation overhead for the first client that requests each JSP.

 2005 Pearson Education, Inc. All rights reserved First JSP Example Simple JSP example (Fig. 27.1) – Demonstrates Fixed-template data (XHTML markup) Creating a Java object ( java.util.Date ) Automatic conversion of JSP expression to a String meta element to refresh Web page at specified interval – First invocation of clock.jsp Notice the delay while: – JSP container translates the JSP into a servlet – JSP container compiles the servlet – JSP container executes the servlet Subsequent invocations should not experience the same delay

 2005 Pearson Education, Inc. All rights reserved. 16 Outline clock.jsp (1 of 2) Line 9 Line 24 meta element refreshes the Web page every 60 seconds Creates Date object that is converted to a String implicitly and displayed in paragraph ( p ) element

 2005 Pearson Education, Inc. All rights reserved. 17 Outline clock.jsp (2 of 2) Program output

 2005 Pearson Education, Inc. All rights reserved. 18 Software Engineering Observation 27.2 JavaServer Pages are easier to implement than servlets when the response to a client request consists primarily of markup that remains constant between requests.

 2005 Pearson Education, Inc. All rights reserved. 19 Software Engineering Observation 27.3 The JSP container converts the result of every JSP expression into a string that is output as part of the response to the client.

 2005 Pearson Education, Inc. All rights reserved Implicit Objects Implicit Objects – Provide access to many servlet capabilities within a JSP – Four scopes Application scope – Objects owned by the container application – Any servlet or JSP can manipulate these objects Page scope – Objects that exist only in page in which they are defined – Each page has its own instance of these objects

 2005 Pearson Education, Inc. All rights reserved Implicit Objects (Cont.) Request scope – Objects exist for duration of client request – Objects go out of scope when response sent to client Session scope – Objects exist for duration of client’s browsing session – Objects go out of scope when client terminates session or when session timeout occurs

 2005 Pearson Education, Inc. All rights reserved. 22 Fig | JSP implicit objects. (1 of 2)

 2005 Pearson Education, Inc. All rights reserved. 23 Fig | JSP implicit objects. (2 of 2)

 2005 Pearson Education, Inc. All rights reserved Scripting Scripting – Dynamically generated content – Insert Java code and logic in JSP using scripting

 2005 Pearson Education, Inc. All rights reserved Scripting Components JSP scripting components – Scriptlets (delimited by ) – Comments JSP comments (delimited by ) XHTML comments (delimited by ) Java’s comments (delimited by // and /* and */ ) – Expressions (delimited by ) – Declarations (delimited by ) – Escape sequences

 2005 Pearson Education, Inc. All rights reserved. 26 Common Programming Error 27.1 Placing a JSP comment or XHTML comment inside a scriptlet is a translation-time syntax error that prevents the JSP from being translated properly.

 2005 Pearson Education, Inc. All rights reserved. 27 Software Engineering Observation 27.4 JSPs should not store client state information in instance variables. Rather, they should use the JSP implicit session object. For more information on how to use the session object, visit Sun’s J2EE tutorial at java.sun.com/j2ee/1.4/docs/tutorial/doc/index.html.

 2005 Pearson Education, Inc. All rights reserved. 28 Fig | JSP escape sequences.

 2005 Pearson Education, Inc. All rights reserved Scripting Example Demonstrate basic scripting capabilities – Responding to get requests

 2005 Pearson Education, Inc. All rights reserved. 30 Software Engineering Observation 27.5 Scriptlets, expressions and fixed-template data can be intermixed in a JSP to create different responses based on the information in a request.

 2005 Pearson Education, Inc. All rights reserved. 31 Outline welcome.jsp (1 of 3) Lines Line 19 Line 26 Scriptlet used to insert Java code Use request implicit object to get parameter JSP expression

 2005 Pearson Education, Inc. All rights reserved. 32 Outline welcome.jsp (2 of 3) Lines and lines Scriptlets used to insert Java code

 2005 Pearson Education, Inc. All rights reserved. 33 Outline welcome.jsp (3 of 3) Program output

 2005 Pearson Education, Inc. All rights reserved. 34 Error-Prevention Tip 27.1 It is sometimes difficult to debug errors in a JSP, because the line numbers reported by a JSP container normally refer to the servlet that represents the translated JSP, not the original JSP line numbers. Program development environments enable JSPs to be compiled in the environment, so you can see syntax error messages. These messages include the statement in the servlet that represents the translated JSP, which can be helpful in determining the error.

 2005 Pearson Education, Inc. All rights reserved. 35 Error-Prevention Tip 27.2 Many JSP containers store the source code for the servlets that represent the translated JSPs. For example, the Tomcat installation directory contains a subdirectory called work in which you can find the source code for the servlets translated by Tomcat. Recall from Chapter 26 that the log files located in the logs subdirectory of the Tomcat installation directory are also helpful for determining the errors.

 2005 Pearson Education, Inc. All rights reserved. 36 Error-Prevention Tip 27.3 Always put the closing brace for the if statement and the else in the same scriptlet.

 2005 Pearson Education, Inc. All rights reserved Standard Actions JSP standard actions – Provide access to common tasks performed in a JSP Including content from other resources Forwarding requests to other resources Interacting with JavaBeans – JSP containers process actions at request time – Delimited by and

 2005 Pearson Education, Inc. All rights reserved. 38 Fig | JSP standard actions. (1 of 2)

 2005 Pearson Education, Inc. All rights reserved. 39 Fig | JSP standard actions. (2 of 2)

 2005 Pearson Education, Inc. All rights reserved Action action – Enables dynamic content to be included in a JSP – More flexible than include directive Requires more overhead when page contents change frequently

 2005 Pearson Education, Inc. All rights reserved. 41 Software Engineering Observation 27.6 According to the JavaServer Pages 2.0 specification, a JSP container is allowed to determine whether a resource included with the include directive has changed. If so, the container can recompile the JSP that included the resource. However, the specification does not provide a mechanism to indicate a change in an included resource to the container.

 2005 Pearson Education, Inc. All rights reserved. 42 Performance Tip 27.2 The action is more flexible than the include directive, but requires more overhead when page contents change frequently. Use the action only when dynamic content is necessary.

 2005 Pearson Education, Inc. All rights reserved. 43 Common Programming Error 27.2 Specifying in a action a page that is not part of the same Web application is a request-time error—the action will not include any content.

 2005 Pearson Education, Inc. All rights reserved. 44 Fig | Action attributes.

 2005 Pearson Education, Inc. All rights reserved. 45 Outline include.jsp (1 of 3)

 2005 Pearson Education, Inc. All rights reserved. 46 Outline include.jsp (2 of 3) Lines Line 45 Lines Use JSP include action to include banner.html Use JSP include action to include toc.html Use JSP include action to include clock2.jsp

 2005 Pearson Education, Inc. All rights reserved. 47 Outline include.jsp (3 of 3) Program output

 2005 Pearson Education, Inc. All rights reserved. 48 Outline banner.html

 2005 Pearson Education, Inc. All rights reserved. 49 Outline toc.html

 2005 Pearson Education, Inc. All rights reserved. 50 Outline clock2.jsp Line 14 Lines Line 25 Format Date with specified DataFormat Use request object’s getLocale method to obtain the client’s Locale Invoke DateFormat static method getDateTimeInstance to obtain a DataFormat object for the specified Locale

 2005 Pearson Education, Inc. All rights reserved Action action – Enables JSP to forward request to different resources Forward requests to resources in same context action – Specifies name-value pairs of information Name-value pairs are passed to other actions

 2005 Pearson Education, Inc. All rights reserved. 52 Software Engineering Observation 27.7 When using the action, the resource to which the request will be forwarded must be in the same context (Web application) as the JSP that originally received the request.

 2005 Pearson Education, Inc. All rights reserved. 53 Outline forward1.jsp (1 of 2) Line 14 Lines Use request implicit object to get parameter Forward request to forward2.jsp

 2005 Pearson Education, Inc. All rights reserved. 54 Outline forward1.jsp (2 of 2) Program output

 2005 Pearson Education, Inc. All rights reserved. 55 Outline forward2.jsp (1 of 2) Line 21 Line 28 Receive request from forward1.jsp, then get firstName parameter from request Get date parameter from request

 2005 Pearson Education, Inc. All rights reserved. 56 Outline forward2.jsp (2 of 2) Program output

 2005 Pearson Education, Inc. All rights reserved Action action – Enables JSP to manipulate Java object Creates Java object or locates an existing object for use in JSP

 2005 Pearson Education, Inc. All rights reserved. 58 Common Programming Error 27.3 One or both of the attributes class and type must be specified—otherwise, a translation-time error occurs.

 2005 Pearson Education, Inc. All rights reserved. 59 Fig | Attributes of the action.

 2005 Pearson Education, Inc. All rights reserved. 60 Outline Rotator.java (1 of 2) Lines Return image file name for book cover image

 2005 Pearson Education, Inc. All rights reserved. 61 Outline Rotator.java (2 of 2) Lines Lines Return hyperlink to book at Amazon.com Update Rotator so subsequent calls to getImage and getLink return information for different advertisements

 2005 Pearson Education, Inc. All rights reserved. 62 Outline adrotator.jsp (1 of 2) Lines 7-8 Line 19 Lines Use jsp:useBean action to obtain reference to Rotator object Invoke Rotator ’s nextAd method Define hyperlink to Amazon.com site

 2005 Pearson Education, Inc. All rights reserved. 63 Outline adrotator.jsp (2 of 2) Program output

 2005 Pearson Education, Inc. All rights reserved Action (Cont.) Action – Attribute name Specify the bean object to manipulate – Attribute property Specify the property to get – Replace action with JSP expressions

 2005 Pearson Education, Inc. All rights reserved. 65 Software Engineering Observation 27.8 Action can use request-parameter values to set JavaBean properties of the following types: String s, primitive types ( boolean, byte, char, short, int, long, float and double ) and type-wrapper classes ( Boolean, Byte, Character, Short, Integer, Long, Float and Double ). See Fig for an example.

 2005 Pearson Education, Inc. All rights reserved. 66 Fig | Attributes of the action.

 2005 Pearson Education, Inc. All rights reserved. 67 Common Programming Error 27.4 Conversion errors occur if you use action ’s value attribute to set JavaBean property types that cannot be set with request parameters.

 2005 Pearson Education, Inc. All rights reserved Directives JSP directives – Messages to JSP container – Enable programmer to: Specify page settings Include content from other resources Specify custom-tag libraries – Delimited by

 2005 Pearson Education, Inc. All rights reserved. 69 Fig | JSP directives.

 2005 Pearson Education, Inc. All rights reserved page Directive JSP page directive – Specifies JSP’s global settings in JSP container

 2005 Pearson Education, Inc. All rights reserved. 71 Common Programming Error 27.5 Providing multiple page directives with one or more repeated attributes in common is a JSP translation-time error, unless the values for all repeated attributes are identical. Also, providing a page directive with an attribute or value that is not recognized is a JSP translation-time error.

 2005 Pearson Education, Inc. All rights reserved. 72 Software Engineering Observation 27.9 According to the JSP specification, section , the extends attribute “should not be used without careful consideration as it restricts the ability of the JSP container to provide specialized superclasses that may improve on the quality of rendered service.” Remember that a Java class can extend exactly one other class. If your JSP specifies an explicit superclass, the JSP container cannot translate your JSP into a subclass of one of the container application’s own enhanced servlet classes.

 2005 Pearson Education, Inc. All rights reserved. 73 Fig | Attributes of the page directive. (1 or 3)

 2005 Pearson Education, Inc. All rights reserved. 74 Fig | Attributes of the page directive. (2 or 3)

 2005 Pearson Education, Inc. All rights reserved. 75 Fig | Attributes of the page directive. (3 or 3)

 2005 Pearson Education, Inc. All rights reserved. 76 Common Programming Error 27.6 Using JSP implicit object session in a JSP that does not have its page directive attribute session set to true is a translation-time error.

 2005 Pearson Education, Inc. All rights reserved include Directive JSP include directive – Includes content of another resource at JSP translation time Not as flexible as action

 2005 Pearson Education, Inc. All rights reserved. 78 Outline includeDirective.j sp (1 of 3)

 2005 Pearson Education, Inc. All rights reserved. 79 Outline includeDirective.j sp (2 of 3) Line 34 Line 40 Line 44 Use include directive to include banner.html Use include directive to include toc.html Use include directive to include clock2.jsp

 2005 Pearson Education, Inc. All rights reserved. 80 Outline includeDirective.j sp (3 of 3) Program output

 2005 Pearson Education, Inc. All rights reserved Case Study: Guest Book Demonstrate – Action – JSP page directive – JSP error pages – Use of JDBC

 2005 Pearson Education, Inc. All rights reserved. 82 Outline GuestBean.java (1 of 2) Lines 7-9 GuestBean declares three guest properties: firstName, lastName and

 2005 Pearson Education, Inc. All rights reserved. 83 Outline GuestBean.java (2 of 2)

 2005 Pearson Education, Inc. All rights reserved. 84 Outline GuestDataBean.java (1 of 3) Line 19 Line 22 Line 23 Line 24 Line 25 Load MySQL driverCreate a CachedRowSet object using Sun’s reference implementation CachedRowSetImpl Set the CachedRowSet ’s database URL property Set the CachedRowSet ’s database username property Set the CachedRowSet ’s database password property

 2005 Pearson Education, Inc. All rights reserved. 85 Outline GuestDataBean.java (2 of 3) Lines Line 30 Line 38 Lines Set the CachedRowSet ’s database command property Execute the query specified by the command property Move the CachedRowSet ’s cursor before the first row Create the GuestBean objects for each row in the CachedRowSet

 2005 Pearson Education, Inc. All rights reserved. 86 Outline GuestDataBean.java (3 of 3) Line 58 Lines Line 64 Line 65 Line 66 Invoke the CachedRowSet ’s moveToInsertRow method to remember the current row and move the cursor to the insert row Invoke the CachedRowSet ’s updateString method to update the column values Invoke the CachedRowSet ’s insertRow method to insert the row into the rowset Invoke the CachedRowSet ’s moveToCurrentRow method to move the cursor back to the current row Invoke the CachedRowSet ’s acceptChanges method to propagates the changes in the rowset to the underlying database

 2005 Pearson Education, Inc. All rights reserved. 87 Outline guestBookLogin.jsp (1 of 3) Line 8 Lines page directive defines information that is globally available in JSP Use jsp:useBean actions to obtain references to GuestBean and GuestDataBean objects

 2005 Pearson Education, Inc. All rights reserved. 88 Outline guestBookLogin.jsp (2 of 3) Line 34 Lines Set properties of GuestBean with request parameter values, because the input elements have the same names as the GuestBean properties Verify that the user fills in all the entries, including first name, last name and

 2005 Pearson Education, Inc. All rights reserved. 89 Outline guestBookLogin.jsp (3 of 3) Line 74 Line 77 Forward request to guestBookView.jsp Add GuestBean guest to GuestDataBean guestData

 2005 Pearson Education, Inc. All rights reserved Case Study: Guest Book (Cont.) Line 34 – Specify “*” for attribute property – Match request parameters to properties – Can set the properties individually

 2005 Pearson Education, Inc. All rights reserved. 91 Outline guestBookView.jsp (1 of 2) Lines 9 and 10 Lines Use page directive import to specify Java classes and packages that are used in JSP context Use jsp:useBean action to obtain reference to GuestDataBean

 2005 Pearson Education, Inc. All rights reserved. 92 Outline guestBookView.jsp (2 of 2) Lines Use scriptlet and expressions to display last name, first name and address for all guests

 2005 Pearson Education, Inc. All rights reserved. 93 Outline guestBookErrorPage.jsp (1 of 3) Line 8 Use page directive isErrorPage to specify that guestBookError- Page is an error page

 2005 Pearson Education, Inc. All rights reserved. 94 Outline guestBookErrorPage.jsp (2 of 3) Lines 28 and 36 Use implicit object exception to determine error to be displayed

 2005 Pearson Education, Inc. All rights reserved. 95 Outline guestBookErrorPage.jsp (3 of 3) Line 60 Display the actual error message from the exception

 2005 Pearson Education, Inc. All rights reserved. 96 Fig | JSP guest book sample output windows. (1 of 3)

 2005 Pearson Education, Inc. All rights reserved. 97 Fig | JSP guest book sample output windows. (2 of 3)

 2005 Pearson Education, Inc. All rights reserved. 98 Fig | JSP guest book sample output windows. (2 of 3)