[JAVA][The Java EE 5 Tutorial].pdf

(9265 KB) Pobierz
The Java™ EE 5
Tutorial
For Sun Java System Application Server Platform Edition 9
Jennifer Ball
Debbie Carson
Ian Evans
Scott Fordin
Kim Haase
Eric Jendrock
June 16, 2006
Copyright © 2006 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A.
All rights reserved.U.S. Government Rights - Commercial software. Government users are subject to the
Sun Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its supple-
ments.
This distribution may include materials developed by third parties.
Sun, Sun Microsystems, the Sun logo, Java, JavaBeans, JavaServer, JavaServer Pages, Enterprise Java-
Beans, Java Naming and Directory Interface, JavaMail, JDBC, EJB, JSP, J2EE, J2SE, “Write Once, Run
Anywhere”, and the Java Coffee Cup logo are trademarks or registered trademarks of Sun Microsystems,
Inc. in the U.S. and other countries.
Unless otherwise licensed, software code in all technical materials herein (including articles, FAQs, sam-
ples) is provided under this License.
Products covered by and information contained in this service manual are controlled by U.S. Export Con-
trol laws and may be subject to the export or import laws in other countries. Nuclear, missile, chemical
biological weapons or nuclear maritime end uses or end users, whether direct or indirect, are strictly pro-
hibited. Export or reexport to countries subject to U.S. embargo or to entities identified on U.S. export
exclusion lists, including, but not limited to, the denied persons and specially designated nationals lists is
strictly prohibited.
DOCUMENTATION IS PROVIDED "AS IS" AND ALL EXPRESS OR IMPLIED CONDITIONS,
REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MER-
CHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE
DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE
LEGALLY INVALID.
Copyright © 2006 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, États-
Unis. Tous droits réservés.
Droits du gouvernement américain, utlisateurs gouvernmentaux - logiciel commercial. Les utilisateurs
gouvernmentaux sont soumis au contrat de licence standard de Sun Microsystems, Inc., ainsi qu aux dis-
positions en vigueur de la FAR [ (Federal Acquisition Regulations) et des suppléments à celles-ci.
Cette distribution peut comprendre des composants développés pardes tierces parties.
Sun, Sun Microsystems, le logo Sun, Java, JavaBeans, JavaServer, JavaServer Pages, Enterprise Java-
Beans, Java Naming and Directory Interface, JavaMail, JDBC, EJB, JSP, J2EE, J2SE, “Write Once, Run
Anywhere”, et le logo Java Coffee Cup sont des marques de fabrique ou des marques déposées de Sun
Microsystems, Inc. aux États-Unis et dans d’autres pays.
A moins qu’autrement autorisé, le code de logiciel en tous les matériaux techniques dans le présent (arti-
cles y compris, FAQs, échantillons) est fourni sous ce permis.
Les produits qui font l’objet de ce manuel d’entretien et les informations qu’il contient sont régis par la
législation américaine en matière de contrôle des exportations et peuvent être soumis au droit d’autres
pays dans le domaine des exportations et importations. Les utilisations finales, ou utilisateurs finaux, pour
des armes nucléaires, des missiles, des armes biologiques et chimiques ou du nucléaire maritime, directe-
ment ou indirectement, sont strictement interdites. Les exportations ou réexportations vers des pays sous
embargo des États-Unis, ou vers des entités figurant sur les listes d’exclusion d’exportation américaines,
y compris, mais de manière non exclusive, la liste de personnes qui font objet d’un ordre de ne pas partic-
iper, d’une façon directe ou indirecte, aux exportations des produits ou des services qui sont régi par la
législation américaine en matière de contrôle des exportations ("U .S. Commerce Department’s Table of
Denial Orders "et la liste de ressortissants spécifiquement désignés ("U.S. Treasury Department of Spe-
cially Designated Nationals and Blocked Persons "),, sont rigoureusement interdites.
LA DOCUMENTATION EST FOURNIE "EN L’ÉTAT" ET TOUTES AUTRES CONDITIONS, DEC-
LARATIONS ET GARANTIES EXPRESSES OU TACITES SONT FORMELLEMENT EXCLUES,
DANS LA MESURE AUTORISEE PAR LA LOI APPLICABLE, Y COMPRIS NOTAMMENT TOUTE
GARANTIE IMPLICITE RELATIVE A LA QUALITE MARCHANDE, A L’APTITUDE A UNE
UTILISATION PARTICULIERE OU A L’ABSENCE DE CONTREFAÇON.
Contents
About This Tutorial. . . . . . . . . . . . . . . . . . . . . . . . . xxvii
Who Should Use This Tutorial
Prerequisites
How to Read This Tutorial
About the Examples
Further Information
How to Print This Tutorial
Typographical Conventions
Feedback
xxvii
xxvii
xxviii
xxx
xxxiv
xxxiv
xxxiv
xxxv
Chapter 1:
Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Java EE Application Model
Distributed Multitiered Applications
Security
Java EE Components
Java EE Clients
Web Components
Business Components
Enterprise Information System Tier
Java EE Containers
Container Services
Container Types
Web Services Support
XML
SOAP Transport Protocol
WSDL Standard Format
UDDI and ebXML Standard Formats
Java EE Application Assembly and Deployment
Packaging Applications
2
3
4
4
4
7
7
9
9
9
10
11
12
13
13
13
14
14
iii
iv
C
ONTENTS
Development Roles
Java EE Product Provider
Tool Provider
Application Component Provider
Application Assembler
Application Deployer and Administrator
Java EE 5 APIs
Enterprise JavaBeans Technology
Java Servlet Technology
JavaServer Pages Technology
JavaServer Pages Standard Tag Library
JavaServer Faces
Java Message Service API
Java Transaction API
JavaMail API
JavaBeans Activation Framework
Java API for XML Processing
Java API for XML Web Services (JAX-WS)
Java Architecture for XML Binding (JAXB)
SOAP with Attachments API for Java
Java API for XML Registries
J2EE Connector Architecture
Java Database Connectivity API
Java Persistence API
Java Naming and Directory Interface
Java Authentication and Authorization Service
Simplified Systems Integration
Sun Java System Application Server Platform Edition 9
Tools
Starting and Stopping the Application Server
Starting the Admin Console
Starting and Stopping the Java DB Database Server
Debugging Java EE Applications
16
16
16
17
17
18
19
19
20
20
20
20
21
21
21
22
22
22
23
23
23
24
24
24
25
26
26
26
27
28
29
30
30
Part One: The Web Tier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .33
Chapter 2:
Getting Started with Web Applications. . . . . . . . . .35
Web Application Life Cycle
Web Modules
Packaging Web Modules
Deploying a WAR File
38
40
42
43
C
ONTENTS
v
44
44
45
47
48
48
49
50
50
51
54
54
55
55
56
Testing Deployed Web Modules
Listing Deployed Web Modules
Updating Web Modules
Undeploying Web Modules
Configuring Web Applications
Mapping URLs to Web Components
Declaring Welcome Files
Setting Initialization Parameters
Mapping Errors to Error Screens
Declaring Resource References
Duke’s Bookstore Examples
Accessing Databases from Web Applications
Populating the Example Database
Creating a Data Source in the Application Server
Further Information
Chapter 3:
Java Servlet Technology . . . . . . . . . . . . . . . . . . . . . 57
What Is a Servlet?
The Example Servlets
Troubleshooting
Servlet Life Cycle
Handling Servlet Life-Cycle Events
Handling Errors
Sharing Information
Using Scope Objects
Controlling Concurrent Access to Shared Resources
Accessing Databases
Initializing a Servlet
Writing Service Methods
Getting Information from Requests
Constructing Responses
Filtering Requests and Responses
Programming Filters
Programming Customized Requests and Responses
Specifying Filter Mappings
Invoking Other Web Resources
Including Other Resources in the Response
Transferring Control to Another Web Component
Accessing the Web Context
Maintaining Client State
57
58
60
61
61
64
64
64
65
67
68
69
70
72
75
75
77
80
82
82
84
85
86
Zgłoś jeśli naruszono regulamin