The J2EE™ 1.4 Tutorial
For Sun Java System Application Server Platform Edition
8.1 2005Q2 UR2
Eric Armstrong
Jennifer Ball
Stephanie Bodoff
Debbie Bode Carson
Ian Evans
Dale Green
Kim Haase
Eric Jendrock
June 7, 2005
Copyright © 2004 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
JavaBeans, 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 Microsys-
tems, 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 © 2004 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
JavaBeans, 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.
iii
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxxi
About This Tutorial. . . . . . . . . . . . . . . . . . . . . . . . . xxxiii
Who Should Use This Tutorial xxxiii
Prerequisites xxxiii
How to Read This Tutorial xxxiv
About the Examples xxxvi
Further Information xxxix
How to Buy This Tutorial xl
How to Print This Tutorial xl
Typographical Conventions xl
Acknowledgments xli
Feedback xlii
Chapter 1: Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Distributed Multitiered Applications 2
J2EE Components 3
J2EE Clients 4
Web Components 6
Business Components 6
Enterprise Information System Tier 8
J2EE Containers 8
Container Services 8
Container Types 9
Web Services Support 10
XML 11
SOAP Transport Protocol 12
WSDL Standard Format 12
UDDI and ebXML Standard Formats 12
Contents
iv CONTENTS
Packaging Applications 13
Development Roles 15
J2EE Product Provider 15
Tool Provider 15
Application Component Provider 16
Application Assembler 16
Application Deployer and Administrator 17
J2EE 1.4 APIs 18
Enterprise JavaBeans Technology 18
Java Servlet Technology 19
JavaServer Pages Technology 19
Java Message Service API 19
Java Transaction API 19
JavaMail API 20
JavaBeans Activation Framework 20
Java API for XML Processing 20
Java API for XML-Based RPC 20
SOAP with Attachments API for Java 21
Java API for XML Registries 21
J2EE Connector Architecture 22
JDBC API 22
Java Naming and Directory Interface 22
Java Authentication and Authorization Service 23
Simplified Systems Integration 24
Sun Java System Application Server Platform Edition 8 24
Technologies 25
Tools 26
Starting and Stopping the Application Server 27
Starting the Admin Console 28
Starting the deploytool Utility 29
Starting and Stopping the PointBase Database Server 29
Debugging J2EE Applications 30
Chapter 2: Understanding XML. . . . . . . . . . . . . . . . . . . . . . . . . .33
Introduction to XML 33
What Is XML? 33
Why Is XML Important? 38
How Can You Use XML? 40
Generating XML Data 43
Writing a Simple XML File 43
CONTENTS v
Defining the Root Element 44
Writing Processing Instructions 48
Introducing an Error 49
Substituting and Inserting Text 50
Creating a Document Type Definition 54
Documents and Data 59
Defining Attributes and Entities in the DTD 59
Referencing Binary Entities 66
Defining Parameter Entities and Conditional Sections 68
Resolving a Naming Conflict 72
Using Namespaces 73
Designing an XML Data Structure 76
Saving Yourself Some Work 77
Attributes and Elements 77
Normalizing Data 79
Normalizing DTDs 81
Summary 81
Chapter 3: Getting Started with Web Applications . . . . . . . . . 83
Web Application Life Cycle 86
Web Modules 88
Packaging Web Modules 90
Deploying Web Modules 92
Listing Deployed Web Modules 95
Updating Web Modules 96
Undeploying Web Modules 98
Configuring Web Applications 99
Mapping URLs to Web Components 99
Declaring Welcome Files 101
Setting Initialization Parameters 102
Mapping Errors to Error Screens 102
Declaring Resource References 103
Duke’s Bookstore Examples 103
Accessing Databases from Web Applications 104
Populating the Example Database 105
Creating a Data Source in the Application Server 105
Specifying a Web Application’s Resource Reference 106
Mapping the Resource Reference to a Data Source 107
Further Information 107