The Java EE 5 Tutorial
For Sun Java System Application Server 9.1
Part No: 821–1743–10
September 2010 (originally published 2007)
Copyright © 2010, Oracle and/or its aliates. All rights reserved.
This software and related documentation are provided under a license agreement containing restrictions on use and disclosure and are protected by intellectual
property laws. Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license,
transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, or decompilation of this software,
unless required by law for interoperability, is prohibited.
The information contained herein is subject to change without notice and is not warranted to be error-free. If you nd any errors, please report them to us in writing.
If this is software or related software documentation that is delivered to the U.S. Government or anyone licensing it on behalf of the U.S. Government, the following
notice is applicable:
U.S. GOVERNMENT RIGHTS Programs, software, databases, and related documentation and technical data delivered to U.S. Government customers are
“commercial computer software” or “commercial technical data” pursuant to the applicable Federal Acquisition Regulation and agency-specic supplemental
regulations. As such, the use, duplication, disclosure, modication, and adaptation shall be subject to the restrictions and license terms set forth in the applicable
Government contract, and, to the extent applicable by the terms of the Government contract, the additional rights set forth in FAR 52.227-19, Commercial
Computer Software License (December 2007). Oracle America, Inc., 500 Oracle Parkway, Redwood City, CA 94065.
This software or hardware is developed for general use in a variety of information management applications. It is not developed or intended for use in any inherently
dangerous applications, including applications which may create a risk of personal injury. If you use this software or hardware in dangerous applications, then you
shall be responsible to take all appropriate fail-safe, backup, redundancy, and other measures to ensure its safe use. Oracle Corporation and its aliates disclaim any
liability for any damages caused by use of this software or hardware in dangerous applications.
Oracle and Java are registered trademarks of Oracle and/or its aliates. Other names may be trademarks of their respective owners.
AMD, Opteron, the AMD logo, and the AMD Opteron logo are trademarks or registered trademarks of Advanced Micro Devices. Intel and Intel Xeon are
trademarks or registered trademarks of Intel Corporation. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC
International, Inc. UNIX is a registered trademark licensed through X/Open Company, Ltd.
This software or hardware and documentation may provide access to or information on content, products, and services from third parties. Oracle Corporation and
its aliates are not responsible for and expressly disclaim all warranties of any kind with respect to third-party content, products, and services. Oracle Corporation
and its aliates will not be responsible for any loss, costs, or damages incurred due to your access to or use of third-party content, products, or services.
100921@24661
Contents
Preface ...................................................................................................................................................29
Part I Introduction .........................................................................................................................................37
1 Overview ...............................................................................................................................................39
Java EE Application Model ................................................................................................................. 40
Distributed Multitiered Applications ............................................................................................... 40
Security .......................................................................................................................................... 41
Java EE Components ................................................................................................................... 42
Java EE Clients .............................................................................................................................. 42
Web Components ........................................................................................................................ 44
Business Components ................................................................................................................. 45
Enterprise Information System Tier .......................................................................................... 46
Java EE Containers .............................................................................................................................. 46
Container Services ....................................................................................................................... 47
Container Types ........................................................................................................................... 47
Web Services Support ......................................................................................................................... 49
XML ............................................................................................................................................... 49
SOAP Transport Protocol ...........................................................................................................50
WSDL Standard Format ..............................................................................................................50
UDDI and ebXML Standard Formats ....................................................................................... 50
Java EE Application Assembly and Deployment ............................................................................. 50
Packaging Applications ...................................................................................................................... 51
Development Roles ............................................................................................................................. 52
Java EE Product Provider ............................................................................................................ 53
Tool Provider ................................................................................................................................ 53
Application Component Provider ............................................................................................. 53
3
Application Assembler ................................................................................................................ 54
Application Deployer and Administrator ................................................................................. 54
Java EE 5 APIs ...................................................................................................................................... 55
Enterprise JavaBeans Technology .............................................................................................. 55
Java Servlet Technology .............................................................................................................. 56
JavaServer Pages Technology ..................................................................................................... 56
JavaServer Pages Standard Tag Library ..................................................................................... 56
JavaServer Faces ........................................................................................................................... 57
Java Message Service API ............................................................................................................ 57
Java Transaction API ................................................................................................................... 57
JavaMail API ................................................................................................................................. 57
JavaBeans Activation Framework .............................................................................................. 58
Java API for XML Processing ..................................................................................................... 58
Java API for XML Web Services (JAX-WS) .............................................................................. 58
Java Architecture for XML Binding (JAXB) ............................................................................. 59
SOAP with Attachments API for Java ........................................................................................ 59
Java API for XML Registries ....................................................................................................... 59
J2EE Connector Architecture ..................................................................................................... 59
Java Database Connectivity API ................................................................................................. 60
Java Persistence API ..................................................................................................................... 60
Java Naming and Directory Interface ........................................................................................ 60
Java Authentication and Authorization Service ....................................................................... 61
Simplied Systems Integration ................................................................................................... 61
Sun Java System Application Server 9.1 ............................................................................................ 62
Tools .............................................................................................................................................. 62
2 Using the Tutorial Examples ..............................................................................................................65
Required Software ............................................................................................................................... 65
Tutorial Bundle ............................................................................................................................ 65
Java Platform, Standard Edition ................................................................................................. 66
Sun Java System Application Server 9.1 ..................................................................................... 66
NetBeans IDE ............................................................................................................................... 67
Apache Ant ................................................................................................................................... 67
Starting and Stopping the Application Server .................................................................................. 68
Starting the Admin Console ............................................................................................................... 69
Contents
The Java EE 5 Tutorial • September 2010 (originally published 2007)4
Starting and Stopping the Java DB Database Server ........................................................................ 69
Building the Examples ........................................................................................................................ 69
Building the Examples Using NetBeans IDE ............................................................................ 69
Building the Examples on the Command-Line Using Ant ..................................................... 70
Tutorial Example Directory Structure .............................................................................................. 71
Debugging Java EE Applications ....................................................................................................... 72
Using the Server Log .................................................................................................................... 72
Using a Debugger ......................................................................................................................... 72
Part II TheWeb Tier ......................................................................................................................................... 75
3 Getting Started with Web Applications ........................................................................................... 77
Web Applications ................................................................................................................................ 77
Web Application Life Cycle ................................................................................................................ 80
Web Modules ....................................................................................................................................... 81
Packaging Web Modules .............................................................................................................83
Deploying a WAR File ................................................................................................................. 84
Testing Deployed Web Modules ................................................................................................ 85
Listing Deployed Web Modules ................................................................................................. 86
Updating Web Modules ..............................................................................................................86
Undeploying Web Modules ........................................................................................................ 88
Conguring Web Applications .......................................................................................................... 89
Mapping URLs to Web Components ........................................................................................ 89
Declaring Welcome Files ............................................................................................................ 91
Setting Initialization Parameters ................................................................................................ 92
Mapping Errors to Error Screens ............................................................................................... 93
Declaring Resource References .................................................................................................. 94
Duke’s Bookstore Examples ............................................................................................................... 96
Accessing Databases from Web Applications .................................................................................. 97
Populating the Example Database ............................................................................................. 97
Creating a Data Source in the Application Server .................................................................... 97
Further Information about Web Applications ................................................................................. 98
Contents
5