Copyright Š 2002 ProsoftTraining. All rights reserved.
JavaServer Pages
Copyright Š 2002 ProsoftTraining. All rights reserved.
Lesson 1:
Introduction to
JavaServer Pages
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
What Is
Enterprise JavaBeans (EJB)?
â€ĸ EJB = An architecture for deploying
component-based distributed applications
– J2EE-compliant application servers
What Are
Java 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
What Is JSP?
â€ĸ Server-side programming environment
– Contains normal HTML with special syntax
that allows dynamic content
Web Application Technologies
â€ĸ Common Gateway Interface (CGI)
â€ĸ Server extensions
â€ĸ Server-side scripting
– ColdFusion
– PHP Hypertext Preprocessor (PHP)
JSP
Advantages 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
Basic
JSP Syntax
â€ĸ Script blocks
<% //Java code %>
â€ĸ JSP files with comments
<%-- JSP comment --%>
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
Copyright Š 2002 ProsoftTraining. All rights reserved.
Lesson 2:
JSP Fundamentals
Objectives
â€ĸ Describe various styles of JSP syntax
â€ĸ Use JSP expressions
â€ĸ Use JSP scriptlets
â€ĸ Use JSP declarations
â€ĸ Use predefined variables
Evaluating
Java Expressions
â€ĸ Syntax:
<%= new java.util.Date( ) %>
Using JSP Scriptlets
â€ĸ Scriptlets allow you to:
– Perform complex operations within a JSP
document
– Intersperse blocks of Java code with
normal HTML
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 %>
Using JSP
Predefined 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
Summary
īƒŧ Describe various styles of JSP syntax
īƒŧ Use JSP expressions
īƒŧ Use JSP scriptlets
īƒŧ Use JSP declarations
īƒŧ Use predefined variables
Copyright Š 2002 ProsoftTraining. All rights reserved.
Lesson 3:
JSP Directives
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
Introduction
to 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
Including
Files in JSP
â€ĸ Using the include directive
â€ĸ Using the jsp:include element
Using the
jsp: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
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
Copyright Š 2002 ProsoftTraining. All rights reserved.
Lesson 4:
JSP and JavaBeans
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
Component-Centric
Architecture
â€ĸ Component-centric architecture:
– Allows for handling complexity
– Divides complex systems into components
JavaBeans
Java
server
Database
server
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
Rules for
Constructing JavaBeans
â€ĸ Class
â€ĸ Constructor
â€ĸ Property
â€ĸ Methods
– Regular methods
– Access methods
The JavaBean
Serializable Interface
â€ĸ When a JavaBean is serialized, its property
values are frozen
â€ĸ To make the JavaBean serializable, it should
implement the Serializable interface
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
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
Copyright Š 2002 ProsoftTraining. All rights reserved.
Lesson 5:
JSP Custom Tags
and Tag Libraries
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
Why Use
Tag 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
Using
Custom Tags
â€ĸ Using a tag library
– The number of pre-existing tag libraries is
growing
Creating JSP
Custom 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
Using Custom
Tags in JSP Files
â€ĸ Key elements of a custom tag:
– Tag name
– Attributes
– Nesting
– Body content
Tag Handlers
Tag
Library Descriptor
â€ĸ Root element = <taglib>
â€ĸ Subelements = tlibversion
shortname
info
â€ĸ Deploying tag libraries
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
Copyright Š 2002 ProsoftTraining. All rights reserved.
Lesson 6:
JSP and Java Servlets
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
Servlets
â€ĸ Java servlets = Java classes that implement
the javax.servlet.Servlet interface
â€ĸ Servlets have no main method for handling
requests
– Using the GET method
Servlets vs. JSP
â€ĸ Manageability problems with servlets
â€ĸ How can JSP help?
Web
Application Architecture
â€ĸ Presentation layer
â€ĸ Application layer
â€ĸ Control layer
MVC
Design Pattern
JSP vs. Servlet Architecture
â€ĸ Model 1 architecture
â€ĸ Model 2 architecture
â€ĸ Model 1 and Model 2 architecture trade-offs
Model 1
Architecture
Model 2
Architecture
Page-Centric Design
Servlet-Centric Design
Controlling the Flow
with 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
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
Copyright Š 2002 ProsoftTraining. All rights reserved.
Lesson 7:
JSP,
HTML Forms and Databases
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
Distributed
Multi-Tiered Applications
â€ĸ Client tier
â€ĸ Server tier
â€ĸ Database tier
Steps in a
Typical Web Communication
http://java.sun.com/getjava/download.html
Hypertext
Transfer
Protocol
Host name
Path name
HTML Forms
â€ĸ Text field input
â€ĸ Radio button input
â€ĸ Check box input
â€ĸ Drop-down menu input
â€ĸ Reset and
submit buttons
Request Object
â€ĸ Contains:
– Methods for storing and retrieving attribute
values
– Methods for accessing request parameters
– Methods for retrieving request headers
– Methods for other uses
Relational
Databases
â€ĸ Database Management System (DBMS)
â€ĸ Queries
Structured
Query Language (SQL)
â€ĸ Data Definition Language (DDL)
â€ĸ Data Manipulation Language (DML)
â€ĸ Data Control Language (DCL)
Java Database
Connectivity (JDBC)
â€ĸ Load a JDBC driver
â€ĸ Connect to a database
â€ĸ Execute SQL statements
â€ĸ Disconnect from a database
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
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

005432796.pdf

  • 1.
    Copyright Š 2002ProsoftTraining. All rights reserved. JavaServer Pages
  • 2.
    Copyright Š 2002ProsoftTraining. All rights reserved. Lesson 1: Introduction to JavaServer Pages
  • 3.
    Objectives â€ĸ Define JavaServerPages (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
  • 4.
    What Is Enterprise JavaBeans(EJB)? â€ĸ EJB = An architecture for deploying component-based distributed applications – J2EE-compliant application servers
  • 5.
    What Are Java 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
  • 6.
    What Is JSP? â€ĸServer-side programming environment – Contains normal HTML with special syntax that allows dynamic content
  • 7.
    Web Application Technologies â€ĸCommon Gateway Interface (CGI) â€ĸ Server extensions â€ĸ Server-side scripting – ColdFusion – PHP Hypertext Preprocessor (PHP)
  • 8.
    JSP Advantages 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
  • 9.
    Basic JSP Syntax â€ĸ Scriptblocks <% //Java code %> â€ĸ JSP files with comments <%-- JSP comment --%>
  • 10.
    Summary īƒŧ Define JavaServerPages (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
  • 11.
    Copyright Š 2002ProsoftTraining. All rights reserved. Lesson 2: JSP Fundamentals
  • 12.
    Objectives â€ĸ Describe variousstyles of JSP syntax â€ĸ Use JSP expressions â€ĸ Use JSP scriptlets â€ĸ Use JSP declarations â€ĸ Use predefined variables
  • 13.
  • 14.
    Using JSP Scriptlets â€ĸScriptlets allow you to: – Perform complex operations within a JSP document – Intersperse blocks of Java code with normal HTML
  • 15.
    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 %>
  • 16.
    Using JSP Predefined 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
  • 17.
    Summary īƒŧ Describe variousstyles of JSP syntax īƒŧ Use JSP expressions īƒŧ Use JSP scriptlets īƒŧ Use JSP declarations īƒŧ Use predefined variables
  • 18.
    Copyright Š 2002ProsoftTraining. All rights reserved. Lesson 3: JSP Directives
  • 19.
    Objectives â€ĸ Define JSPdirectives â€ĸ 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
  • 20.
    Introduction to 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
  • 21.
    Including Files in JSP â€ĸUsing the include directive â€ĸ Using the jsp:include element
  • 22.
    Using the jsp: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
  • 23.
    Summary īƒŧ Define JSPdirectives īƒŧ 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
  • 24.
    Copyright Š 2002ProsoftTraining. All rights reserved. Lesson 4: JSP and JavaBeans
  • 25.
    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
  • 26.
    Component-Centric Architecture â€ĸ Component-centric architecture: –Allows for handling complexity – Divides complex systems into components
  • 27.
  • 28.
    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
  • 29.
    Rules for Constructing JavaBeans â€ĸClass â€ĸ Constructor â€ĸ Property â€ĸ Methods – Regular methods – Access methods
  • 30.
    The JavaBean Serializable Interface â€ĸWhen a JavaBean is serialized, its property values are frozen â€ĸ To make the JavaBean serializable, it should implement the Serializable interface
  • 31.
    Accessing JavaBeans Through Scriptletsand 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
  • 32.
    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
  • 33.
    Copyright Š 2002ProsoftTraining. All rights reserved. Lesson 5: JSP Custom Tags and Tag Libraries
  • 34.
    Objectives â€ĸ Describe JSPcustom 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
  • 35.
    Why Use Tag 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
  • 36.
    Using Custom Tags â€ĸ Usinga tag library – The number of pre-existing tag libraries is growing
  • 37.
    Creating JSP Custom TagLibraries â€ĸ 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
  • 38.
    Using Custom Tags inJSP Files â€ĸ Key elements of a custom tag: – Tag name – Attributes – Nesting – Body content
  • 39.
  • 40.
    Tag Library Descriptor â€ĸ Rootelement = <taglib> â€ĸ Subelements = tlibversion shortname info â€ĸ Deploying tag libraries
  • 41.
    Summary īƒŧ Describe JSPcustom 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
  • 42.
    Copyright Š 2002ProsoftTraining. All rights reserved. Lesson 6: JSP and Java Servlets
  • 43.
    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
  • 44.
    Servlets â€ĸ Java servlets= Java classes that implement the javax.servlet.Servlet interface â€ĸ Servlets have no main method for handling requests – Using the GET method
  • 45.
    Servlets vs. JSP â€ĸManageability problems with servlets â€ĸ How can JSP help?
  • 46.
    Web Application Architecture â€ĸ Presentationlayer â€ĸ Application layer â€ĸ Control layer
  • 47.
  • 48.
    JSP vs. ServletArchitecture â€ĸ Model 1 architecture â€ĸ Model 2 architecture â€ĸ Model 1 and Model 2 architecture trade-offs
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
    Controlling the Flow withRequestDispatcher â€ĸ 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
  • 54.
    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
  • 55.
    Copyright Š 2002ProsoftTraining. All rights reserved. Lesson 7: JSP, HTML Forms and Databases
  • 56.
    Objectives â€ĸ Describe thetiers 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
  • 57.
    Distributed Multi-Tiered Applications â€ĸ Clienttier â€ĸ Server tier â€ĸ Database tier
  • 58.
    Steps in a TypicalWeb Communication http://java.sun.com/getjava/download.html Hypertext Transfer Protocol Host name Path name
  • 59.
    HTML Forms â€ĸ Textfield input â€ĸ Radio button input â€ĸ Check box input â€ĸ Drop-down menu input â€ĸ Reset and submit buttons
  • 60.
    Request Object â€ĸ Contains: –Methods for storing and retrieving attribute values – Methods for accessing request parameters – Methods for retrieving request headers – Methods for other uses
  • 61.
  • 62.
    Structured Query Language (SQL) â€ĸData Definition Language (DDL) â€ĸ Data Manipulation Language (DML) â€ĸ Data Control Language (DCL)
  • 63.
    Java Database Connectivity (JDBC) â€ĸLoad a JDBC driver â€ĸ Connect to a database â€ĸ Execute SQL statements â€ĸ Disconnect from a database
  • 64.
    Summary īƒŧ Describe thetiers 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
  • 65.
    JavaServer Pages īƒŧ Introductionto JavaServer Pages īƒŧ JSP Fundamentals īƒŧ JSP Directives īƒŧ JSP and JavaBeans īƒŧ JSP Custom Tags and Tag Libraries īƒŧ JSP and Java Servlets īƒŧ JSP, HTML Forms and Databases