Professional Documents
Culture Documents
Oracle9i Buid J2EE Applications
Oracle9i Buid J2EE Applications
D16501GC10
Edition 1.0
March 2003
D37834
Authors
Lynn Munsinger
Sunitha Patel
Glenn Stokol
Technical Contributors
and Reviewers
Anna Atkinson
William Bates
Scott Brewton
Steve Button
Olivier Caudron
Sam Chou
Rob Clark
Ken Cooper
Scott Davies
Edward Dowgiallo
Julie Fowler
Rob Giardina
Craig Hollister
Taj-ul Islam
Peter Laseau
Wendy Liau
Glenn Maslen
Peter Moskovits
Monica Motley-Mosser
Steve Muench
Rama Notowidigdo
Debabrata Panda
Ashesh Parekh
Nagavalli Pataballa
Ian Purvis
Holger Dindler-Rasmussen
Prasad Shiva
Raghav Srinivasan
Janet Stern
Ulrich Vogel
Prasad Yammanur
Lelia Yin
Publisher
Nita K. S. Brozowski
Contents
Preface
1
Introduction
Course Objectives 1-2
Course Environment 1-4
Course Overview 1-5
About the Course Applications 1-8
Order Entry Schema 1-9
Human Resources (HR) Schema 1-10
HR Application Flow Diagram 1-11
Summary 1-12
2 J2EE Overview
Objectives 2-2
Java 2, Enterprise Edition Platform 2-3
The J2EE Platform 2-4
Benefits of the J2EE Platform 2-5
J2EE Components 2-7
J2EE 1.3 Components 2-9
J2EE Architecture 2-10
Client Tier Components 2-12
J2EE Web Tier Components 2-13
What Is a Servlet? 2-16
What Is a JavaServer Page (JSP)? 2-16
Web Tier Components: Summary 2-17
Business Tier Components 2-18
Enterprise JavaBeans (EJB) 2-19
J2EE Communication APIs 2-20
J2EE Server 2-21
Oracle9iAS Containers for J2EE 2-23
J2EE Applications 2-24
Packaging J2EE Application Components 2-25
JARs 2-26
WARs 2-27
EJB JARs 2-28
EARs 2-29
Deployment Path for a J2EE Application: Example 2-30
OC4J Architecture 2-31
OC4J Server Configuration Files 2-32
Relation of Configuration Files 2-33
Data Sources 2-34
Utilizing Data Sources 2-35
OC4J Deployment 2-36
iii
iv
SingleThreadModel 4-21
JDeveloper Environment 4-22
Servlet Mapping 4-23
Servlet Mapping in Jdeveloper 4-24
Invoking a Servlet 4-25
Specifying J2EE Web Module Settings 4-26
Creating a Connection to Oracle9iAS 4-27
Deploying to OC4J 4-28
Summary 4-29
Practice 4-1, 4-2, and 4-3 Overview 4-30
5 Accessing the Database with Servlets
Objectives 5-2
Review of JDBC 5-3
Querying in JDBC 5-4
JDBC and Servlets 5-5
Synchronizing Shared Resources 5-6
Improving Database Performance 5-7
Connection Pooling 5-9
Data Sources 5-10
Data Source Definition 5-11
Example: data-sources.xml 5-12
Using Data Sources 5-13
Summary 5-14
Practice 5-1 Overview 5-15
6 Using Advanced Techniques in Servlets
Objectives 6-2
Overview 6-3
HTTP Headers 6-4
Request Headers 6-5
Sending a Response 6-6
Response Headers 6-7
Setting Status Codes 6-8
Example 6-9
Sending Multimedia Content 6-10
Cookies 6-12
Setting Cookies 6-13
Retrieving Cookies 6-14
About State Preservation 6-15
State Preservation: Example 6-16
ServletContext 6-17
RequestDispatcher 6-18
RequestDispatcher Example 6-19
Servlet Filters 6-20
Using Filters 6-21
doFilter () Method 6-22
Configuring Filters 6-24
Application Lifecycle Events 6-25
ServletContext Events 6-26
HttpSession Events 6-27
Example of an Event Listener 6-28
Error Handling 6-29
Summary 6-30
Practice 6-1 and 6-2 Overview 6-31
7 Maintaining State in J2EE Applications
Objectives 7-2
Overview 7-3
Session Basics 7-4
Threading 7-6
URL Rewriting 7-7
HttpSession 7-8
Session Objects 7-9
Session-Based Page Counter 7-10
Session Life Cycle 7-11
Session Tracking in OC4J 7-12
Sessions and Events 7-13
Creating Distributable Applications 7-17
Summary 7-18
Practice 7-1 Overview 7-19
8 Creating the Web Tier: JavaServer Pages
Objectives 8-2
JavaServer Pages 8-3
Comparing Servlets and JSPs 8-4
Invoking JavaServer Pages 8-5
The Date JSP 8-6
The Date Servlet 8-7
Automated JSP Features 8-8
JSP Lifecycle 8-9
Basic JSP Elements 8-10
vi
Declarations 8-11
Expressions 8-12
Scriptlets 8-13
Implicit Objects 8-14
Example 8-16
Directives 8-18
include: Example 8-19
The page Directive 8-20
JSP and JavaBeans 8-22
Using JavaBeans with JSP 8-23
scope Attribute of <jsp:useBean> Tag 8-25
Accessing and Setting Bean Property 8-26
JSP XML Document 8-28
Traditional Syntax Versus XML Syntax 8-29
JDeveloper and JavaServer Pages 8-31
JSP Tag Insight 8-32
Summary 8-33
Practice 8-1, 8-2, and 8-3 Overview 8-34
9 Modularizing JavaServer Pages Development with Tags
Objectives 9-2
Custom Tags 9-3
Creating Custom Tags 9-4
Tag Handlers 9-5
Tag Handler Example 9-6
Tag Handler Lifecycle 9-7
Tag Library Descriptors 9-8
Using a Custom Tag 9-9
Tags with Attributes 9-10
TagExtraInfo Class 9-11
Tag Libraries 9-12
Creating a Custom Tag in JDeveloper 9-13
Creating a Tag Library in JDeveloper 9-14
Creating a Tag Handler in JDeveloper 9-15
Adding Attributes 9-16
Adding Scripting Variables 9-17
Packaging Tag Libraries 9-18
Tag Libraries in JDeveloper 9-19
Registering Tag Libraries 9-20
Using Tag Insight 9-23
Edge Side Include (ESI) Tags 9-24
vii
viii
xi
xiii
xiv
xv
xvi