JavaServer Pages v1 0 PowerPoint 110802

Download Report

Transcript JavaServer Pages v1 0 PowerPoint 110802

JavaServer Pages
Copyright © 2002 ProsoftTraining. All rights reserved.
Lesson 1:
Introduction to
JavaServer Pages
Copyright © 2002 ProsoftTraining. All rights reserved.
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
Lesson 2:
JSP Fundamentals
Copyright © 2002 ProsoftTraining. All rights reserved.
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
Lesson 3:
JSP Directives
Copyright © 2002 ProsoftTraining. All rights reserved.
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
Lesson 4:
JSP and JavaBeans
Copyright © 2002 ProsoftTraining. All rights reserved.
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
Database
server
Java
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
Lesson 5:
JSP Custom Tags
and Tag Libraries
Copyright © 2002 ProsoftTraining. All rights reserved.
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
Lesson 6:
JSP and Java Servlets
Copyright © 2002 ProsoftTraining. All rights reserved.
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
Lesson 7:
JSP,
HTML Forms and Databases
Copyright © 2002 ProsoftTraining. All rights reserved.
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