copyright © 2002 prosofttraining. all rights reserved. javaserver pages
TRANSCRIPT
![Page 1: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/1.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
JavaServer Pages
![Page 2: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/2.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 1:Introduction to
JavaServer Pages
![Page 3: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/3.jpg)
Objectives
• Define JavaServer Pages (JSP)• Define Java servlets• Define Enterprise JavaBeans (EJB)• Compare JSP to other server-side
programming environments• Explain the advantages of JSP• Understand the mechanics of JSP documents• Use basic JSP syntax• Describe how to invoke JSP documents
![Page 4: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/4.jpg)
What IsEnterprise JavaBeans (EJB)?
• EJB = An architecture for deploying component-based distributed applications– J2EE-compliant application servers
![Page 5: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/5.jpg)
What AreJava Servlets?
• Java servlets provide the functionality of the CGI for Java-driven Web applications– Managed and executed on a Web server
that provides a servlet container– Executed within a single JVM and server
process
![Page 6: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/6.jpg)
What Is JSP?
• Server-side programming environment– Contains normal HTML with special syntax
that allows dynamic content
![Page 7: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/7.jpg)
Web Application Technologies
• Common Gateway Interface (CGI)• Server extensions• Server-side scripting
– ColdFusion– PHP Hypertext Preprocessor (PHP)
![Page 8: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/8.jpg)
JSPAdvantages and Mechanics
• Java = powerful programming language– Built-in APIs
• JSP applications are portable• JSP engine locates the JSP document• JSP engine processes the JSP document
into a servlet• JSP engine passes control to servlet engine
![Page 9: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/9.jpg)
BasicJSP Syntax
• Script blocks
<% //Java code %>
• JSP files with comments
<%-- JSP comment --%>
![Page 10: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/10.jpg)
Summary
Define JavaServer Pages (JSP) Define Java servlets Define Enterprise JavaBeans (EJB) Compare JSP to other server-side
programming environments Explain the advantages of JSP Understand the mechanics of JSP documents Use basic JSP syntax Describe how to invoke JSP documents
![Page 11: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/11.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 2:JSP Fundamentals
![Page 12: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/12.jpg)
Objectives
• Describe various styles of JSP syntax• Use JSP expressions• Use JSP scriptlets• Use JSP declarations• Use predefined variables
![Page 13: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/13.jpg)
EvaluatingJava Expressions
• Syntax:
<%= new java.util.Date( ) %>
![Page 14: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/14.jpg)
Using JSP Scriptlets
• Scriptlets allow you to: – Perform complex operations within a JSP
document– Intersperse blocks of Java code with
normal HTML
![Page 15: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/15.jpg)
Using JSP Declarations
• JSP declarations:– Provide a construct in which to declare
methods and variables– Do not produce output– Use the following syntax:
<%! //Java code %>
![Page 16: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/16.jpg)
Using JSPPredefined Variables
• The request variable• The response variable• The out variable• The application variable• The session variable• The config variable• The pageContext variable• The page variable
![Page 17: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/17.jpg)
Summary
Describe various styles of JSP syntax Use JSP expressions Use JSP scriptlets Use JSP declarations Use predefined variables
![Page 18: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/18.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 3:JSP Directives
![Page 19: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/19.jpg)
Objectives
• Define JSP directives• Use the page directive• Use page directive attributes• Use the include directive• Use the jsp:include element• Add and manipulate Java applets in JSP files
using the jsp:plugin element
![Page 20: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/20.jpg)
Introductionto JSP Directives
• The page directive– The import attribute– The language attribute– The contentType attribute– The pageEncoding attribute– The extends attribute– The isThreadSafe attribute– The session attribute– The buffer attribute– The autoFlush attribute– The errorPage attribute– The isErrorPage attribute– The info attribute
![Page 21: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/21.jpg)
IncludingFiles in JSP
• Using the include directive• Using the jsp:include element
![Page 22: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/22.jpg)
Using thejsp:plugin Element
• The jsp:plugin element is used to:– Add Java applets to JSP files– Determine the appropriate tag for the client
browser accessing the JSP file
![Page 23: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/23.jpg)
Summary
Define JSP directives Use the page directive Use page directive attributes Use the include directive Use the jsp:include element Add and manipulate Java applets in JSP files
using the jsp:plugin element
![Page 24: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/24.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 4:JSP and JavaBeans
![Page 25: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/25.jpg)
Objectives
• Define JavaBeans• Explain the concept of component-centric
architecture• Describe the advantages of JavaBeans• Instantiate JavaBeans• Use JSP-JavaBeans tags to access and
manipulate JavaBeans properties• Explain the conventions for constructing
JavaBeans• Use the serializable interface• Access JavaBeans through scripting elements
![Page 26: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/26.jpg)
Component-Centric Architecture
• Component-centric architecture:– Allows for handling complexity– Divides complex systems into components
![Page 27: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/27.jpg)
JavaBeans
Java server
Database server
![Page 28: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/28.jpg)
JSP—JavaBeans Tags
Tag Description
<jsp:useBean> Used to instantiate a JavaBean and create a reference to it
<jsp:getProperty> Used to access a JavaBean property
<jsp:setProperty> Used to modify a JavaBean property
![Page 29: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/29.jpg)
Rules forConstructing JavaBeans
• Class• Constructor• Property• Methods
– Regular methods– Access methods
![Page 30: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/30.jpg)
The JavaBeanSerializable Interface
• When a JavaBean is serialized, its property values are frozen
• To make the JavaBean serializable, it should implement the Serializable interface
![Page 31: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/31.jpg)
Accessing JavaBeans Through Scriptlets and Expressions
• After the <jsp:useBean> tag instantiates a JavaBean and has a reference to it, the JavaBean can be used in scriptlets and expressions throughout the scope of the JavaBean
![Page 32: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/32.jpg)
Summary
Define JavaBeans Explain the concept of component-centric
architecture Describe the advantages of JavaBeans Instantiate JavaBeans Use JSP-JavaBeans tags to access and
manipulate JavaBeans properties Explain the conventions for constructing
JavaBeans Use the serializable interface Access JavaBeans through scripting elements
![Page 33: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/33.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 5:JSP Custom Tagsand Tag Libraries
![Page 34: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/34.jpg)
Objectives
• Describe JSP custom tags• Explain the need for JSP tag libraries• Define and use the taglib directive• Download, install and use a tag library• Create custom handler classes and descriptor
files• Create tag attributes• Use a custom tag• Deploy tag libraries
![Page 35: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/35.jpg)
Why UseTag Libraries?
• Custom tag libraries:– Allow you to create complex objects that
can be used by JSP developers– Allow you to reuse code across multiple
JSP applications
![Page 36: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/36.jpg)
UsingCustom Tags
• Using a tag library– The number of pre-existing tag libraries is
growing
![Page 37: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/37.jpg)
Creating JSPCustom Tag Libraries
• Three steps to creating a custom tag:– Define a tag handler class– Define a tag library descriptor– Define a JSP page that uses the custom tag
• The taglib directive
![Page 38: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/38.jpg)
Using CustomTags in JSP Files
• Key elements of a custom tag:– Tag name– Attributes– Nesting– Body content
![Page 39: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/39.jpg)
Tag Handlers
![Page 40: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/40.jpg)
TagLibrary Descriptor
• Root element = <taglib>• Subelements = tlibversion
shortname info
• Deploying tag libraries
![Page 41: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/41.jpg)
Summary
Describe JSP custom tags Explain the need for JSP tag libraries Define and use the taglib directive Download, install and use a tag library Create custom handler classes and descriptor
files Create tag attributes Use a custom tag Deploy tag libraries
![Page 42: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/42.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 6:JSP and Java Servlets
![Page 43: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/43.jpg)
Objectives
• Define servlets• Write simple servlets• Discuss the difference between servlets and
JSPs• Explain the concept of MVC design pattern• Describe the layers of MVC design pattern• Explain Models 1 and 2 Web application designs• Define the RequestDispatcher interface• Use the RequestDispatcher to dispatch
requests
![Page 44: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/44.jpg)
Servlets
• Java servlets = Java classes that implement the javax.servlet.Servlet interface
• Servlets have no main method for handling requests– Using the GET method
![Page 45: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/45.jpg)
Servlets vs. JSP
• Manageability problems with servlets• How can JSP help?
![Page 46: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/46.jpg)
WebApplication Architecture
• Presentation layer• Application layer• Control layer
![Page 47: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/47.jpg)
MVCDesign Pattern
![Page 48: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/48.jpg)
JSP vs. Servlet Architecture
• Model 1 architecture• Model 2 architecture• Model 1 and Model 2 architecture trade-offs
![Page 49: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/49.jpg)
Model 1Architecture
![Page 50: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/50.jpg)
Model 2Architecture
![Page 51: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/51.jpg)
Page-Centric Design
![Page 52: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/52.jpg)
Servlet-Centric Design
![Page 53: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/53.jpg)
Controlling the Flowwith RequestDispatcher
• Acquiring a RequestDispatcher object• Using the RequestDispatcher object• Where to place the servlets• Incorporating another resource's output in a
servlet• Forwarding a request from a JSP to other
resources
![Page 54: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/54.jpg)
Summary
Define servlets Write simple servlets Discuss the difference between servlets and
JSPs Explain the concept of MVC design pattern Describe the layers of MVC design pattern Explain Models 1 and 2 Web application
designs Define the RequestDispatcher interface Use the RequestDispatcher to dispatch
requests
![Page 55: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/55.jpg)
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 7:JSP,
HTML Forms and Databases
![Page 56: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/56.jpg)
Objectives
• Describe the tiers in a three-tier distributed application
• Discuss a Web communication between tiers• Use HTML forms and their input elements• Use the request object to communicate
between HTML forms and JSP files• Explain the concept of relational databases• Use the main SQL statements• Describe Java Database Connectivity• Connect to a database and access information• Create an example of an HTML form
![Page 57: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/57.jpg)
DistributedMulti-Tiered Applications
• Client tier• Server tier• Database tier
![Page 58: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/58.jpg)
Steps in aTypical Web Communication
http://java.sun.com/getjava/download.html
Hypertext Transfer Protocol
Host name
Path name
![Page 59: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/59.jpg)
HTML Forms
• Text field input
• Radio button input
• Check box input
• Drop-down menu input
• Reset and submit buttons
![Page 60: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/60.jpg)
Request Object
• Contains:– Methods for storing and retrieving attribute
values– Methods for accessing request parameters– Methods for retrieving request headers– Methods for other uses
![Page 61: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/61.jpg)
RelationalDatabases
• Database Management System (DBMS)• Queries
![Page 62: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/62.jpg)
StructuredQuery Language (SQL)
• Data Definition Language (DDL)• Data Manipulation Language (DML)• Data Control Language (DCL)
![Page 63: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/63.jpg)
Java DatabaseConnectivity (JDBC)
• Load a JDBC driver• Connect to a database• Execute SQL statements• Disconnect from a database
![Page 64: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/64.jpg)
Summary
Describe the tiers in a three-tier distributed application
Discuss a Web communication between tiers Use HTML forms and their input elements Use the request object to communicate
between HTML forms and JSP files Explain the concept of relational databases Use the main SQL statements Describe Java Database Connectivity Connect to a database and access information Create an example of an HTML form
![Page 65: Copyright © 2002 ProsoftTraining. All rights reserved. JavaServer Pages](https://reader034.vdocuments.mx/reader034/viewer/2022051620/56649f215503460f94c39863/html5/thumbnails/65.jpg)
JavaServer Pages
Introduction to JavaServer Pages JSP Fundamentals JSP Directives JSP and JavaBeans JSP Custom Tags and Tag Libraries JSP and Java Servlets JSP, HTML Forms and Databases