j2ee tutorial

1.5K 5.5K 0
j2ee tutorial

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

The J2EE™ 1.4 Tutorial Eric Armstrong Jennifer Ball Stephanie Bodoff Debbie Bode Carson Ian Evans Dale Green Kim Haase Eric Jendrock March 31, 2004 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 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 © 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 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. 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 Print This Tutorial xxxix Typographical Conventions xl Acknowledgments xl Feedback xli 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 13 Packaging 13 Contents iv CONTENTS 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 29 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 Defining the Root Element 44 CONTENTS v 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 91 Listing Deployed Web Modules 95 Updating Web Modules 95 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 106 Specifying a Web Application’s Resource Reference 106 Mapping the Resource Reference to a Data Source 107 Further Information 108 vi CONTENTS Chapter 4: Java API for XML Processing . . . . . . . . . . . . . . . . .109 The JAXP APIs 109 An Overview of the Packages 110 The Simple API for XML (SAX) APIs 111 The SAX Packages 114 The Document Object Model (DOM) APIs 114 The DOM Packages 116 The Extensible Stylesheet Language Transformations (XSLT) APIs 117 The XSLT Packages 118 Using the JAXP Libraries 118 Where Do You Go from Here? 118 Chapter 5: Simple API for XML . . . . . . . . . . . . . . . . . . . . . . . . .121 When to Use SAX 122 Echoing an XML File with the SAX Parser 123 Creating the Skeleton 124 Importing Classes 124 Setting Up for I/O 125 Implementing the ContentHandler Interface 125 Setting up the Parser 127 Writing the Output 128 Spacing the Output 128 Handling Content Events 129 Compiling and Running the Program 134 Checking the Output 135 Identifying the Events 136 Compressing the Output 138 Inspecting the Output 140 Documents and Data 141 Adding Additional Event Handlers 141 Identifying the Document’s Location 142 Handling Processing Instructions 144 Summary 145 Handling Errors with the Nonvalidating Parser 145 Displaying Special Characters and CDATA 153 Handling Special Characters 153 Handling Text with XML-Style Syntax 154 Handling CDATA and Other Characters 155 Parsing with a DTD 156 CONTENTS vii DTD’s Effect on the Nonvalidating Parser 156 Tracking Ignorable Whitespace 157 Cleanup 159 Empty Elements, Revisited 159 Echoing Entity References 160 Echoing the External Entity 160 Summarizing Entities 161 Choosing Your Parser Implementation 161 Using the Validating Parser 162 Configuring the Factory 162 Validating with XML Schema 163 Experimenting with Validation Errors 166 Error Handling in the Validating Parser 168 Parsing a Parameterized DTD 168 DTD Warnings 170 Handling Lexical Events 170 How the LexicalHandler Works 171 Working with a LexicalHandler 172 Using the DTDHandler and EntityResolver 177 The DTDHandler API 178 The EntityResolver API 179 Further Information 179 Chapter 6: Document Object Model . . . . . . . . . . . . . . . . . . . 181 When to Use DOM 182 Documents Versus Data 182 Mixed-Content Model 183 A Simpler Model 184 Increasing the Complexity 185 Choosing Your Model 187 Reading XML Data into a DOM 188 Creating the Program 188 Additional Information 192 Looking Ahead 195 Displaying a DOM Hierarchy 195 Convert DomEcho to a GUI App 195 Create Adapters to Display the DOM in a JTree 201 Finishing Up 211 Examining the Structure of a DOM 211 Displaying a Simple Tree 212 viii CONTENTS Displaying a More Complex Tree 214 Finishing Up 220 Constructing a User-Friendly JTree from a DOM 221 Compressing the Tree View 221 Acting on Tree Selections 227 Handling Modifications 237 Finishing Up 237 Creating and Manipulating a DOM 237 Obtaining a DOM from the Factory 237 Normalizing the DOM 241 Other Operations 243 Finishing Up 246 Validating with XML Schema 246 Overview of the Validation Process 247 Configuring the DocumentBuilder Factory 247 Validating with Multiple Namespaces 249 Further Information 252 Chapter 7: Extensible Stylesheet Language Transformations 253 Introducing XSL, XSLT and XPath 254 The JAXP Transformation Packages 254 How XPath Works 255 XPath Expressions 255 The XSLT/XPath Data Model 256 Templates and Contexts 257 Basic XPath Addressing 257 Basic XPath Expressions 258 Combining Index Addresses 259 Wildcards 259 Extended-Path Addressing 260 XPath Data Types and Operators 261 String-Value of an Element 261 XPath Functions 262 Summary 265 Writing Out a DOM as an XML File 265 Reading the XML 266 Creating a Transformer 267 Writing the XML 270 Writing Out a Subtree of the DOM 271 Summary 272 CONTENTS ix Generating XML from an Arbitrary Data Structure 272 Creating a Simple File 273 Creating a Simple Parser 275 Modifying the Parser to Generate SAX Events 277 Using the Parser as a SAXSource 284 Doing the Conversion 286 Transforming XML Data with XSLT 287 Defining a Simple <article> Document Type 287 Creating a Test Document 289 Writing an XSLT Transform 290 Processing the Basic Structure Elements 291 Writing the Basic Program 295 Trimming the Whitespace 297 Processing the Remaining Structure Elements 300 Process Inline (Content) Elements 304 Printing the HTML 309 What Else Can XSLT Do? 309 Transforming from the Command Line with Xalan 311 Concatenating Transformations with a Filter Chain 311 Writing the Program 311 Understanding How the Filter Chain Works 315 Testing the Program 316 Conclusion 318 Further Information 319 Chapter 8: Building Web Services with JAX-RPC . . . . . . . . . . 321 Setting the Port 322 Creating a Simple Web Service and Client with JAX-RPC 322 Coding the Service Endpoint Interface and Implementation Class 324 Building the Service 325 Packaging the Service 326 Specifying the Endpoint Address 328 Deploying the Service 328 Static Stub Client 329 Types Supported by JAX-RPC 332 J2SE SDK Classes 332 Primitives 333 Arrays 333 Value Types 333 JavaBeans Components 334 x CONTENTS Web Service Clients 334 Dynamic Proxy Client 334 Dynamic Invocation Interface (DII) Client 337 Application Client 341 More JAX-RPC Clients 345 Web Services Interoperability (WS-I) and JAX-RPC 345 Further Information 346 Chapter 9: SOAP with Attachments API for Java . . . . . . . . . .347 Overview of SAAJ 348 Messages 348 Connections 352 Tutorial 353 Creating and Sending a Simple Message 354 Adding Content to the Header 363 Adding Content to the SOAPPart Object 364 Adding a Document to the SOAP Body 365 Manipulating Message Content Using SAAJ or DOM APIs 366 Adding Attachments 366 Adding Attributes 369 Using SOAP Faults 375 Code Examples 379 Request.java 380 MyUddiPing.java 381 HeaderExample.java 388 DOMExample.java and DOMSrcExample.java 390 Attachments.java 394 SOAPFaultTest.java 396 Further Information 397 Chapter 10: Java API for XML Registries . . . . . . . . . . . . . . . . . .399 Overview of JAXR 399 What Is a Registry? 399 What Is JAXR? 400 JAXR Architecture 401 Implementing a JAXR Client 403 Establishing a Connection 404 Querying a Registry 409 Managing Registry Data 414 [...]... Software Tutorial Bundle The tutorial example source is contained in the tutorial bundle If you are viewing this online, you need to download tutorial bundle from: http://java.sun.com /j2ee/ 1.4/download.html #tutorial After you have installed the tutorial bundle, the example source code is in the /j2eetutorial14/examples/ directory, with subdirectories for each of the technologies discussed in the tutorial. .. servers The J2EE Tutorial, Second Edition covers the J2EE 1.4 platform and more If you have used the first edition of The J2EE Tutorial you may notice that the second edition is triple the size This reflects a major expansion in the J2EE platform and the availability of two upcoming J2EE technologies in the Sun Java System Application Server Platform Edition 8, the software on which the tutorial is... Java System Application Server Read this tutorial and you will become part of the next wave of J2EE application developers Jeff Jackson Vice President, J2EE and Application Servers Sun Microsystems Santa Clara, CA March 31, 2004 About This Tutorial THE J2EE 1.4 Tutorial is a guide to developing enterprise applications for the Java 2 Platform, Enterprise Edition (J2EE) version 1.4 Here we cover all the... and energy to take on the J2EE 1.4 platform You can increase the scope of the J2EE applications you develop, and your applications will run on the widest possible range of application server products To help you to learn all about the J2EE 1.4 platform, The J2EE Tutorial, Second Edition follows the familiar Java Series tutorial model of concise descriptions of the essential features of each technology... The J2EE Tutorial was released, the Java™ 2 Platform, Enterprise Edition (J2EE) was the new kid on the block Modeled after its forerunner, the Java 2 Platform, Standard Edition (J2SE™), the J2EE platform brought the benefits of “Write Once, Run Anywhere™” API compatibility to enterprise application servers Now at version 1.4 and with widespread conformance in the application server marketplace, the J2EE. .. Here we cover all the things you need to know to make the best use of this tutorial Who Should Use This Tutorial This tutorial is intended for programmers who are interested in developing and deploying J2EE 1.4 applications on the Sun Java System Application Server Platform Edition 8 Prerequisites Before proceeding with this tutorial you should have a good knowledge of the Java programming language... in The Java™ Tutorial, Mary Campione et al., (Addison-Wesley, 2000) In particular, you should be familiar with relational database and security features described in the trails listed in Table 1 Table 1 Prerequisite Trails in The Java™ Tutorial Trail URL JDBC http://java.sun.com/docs/books /tutorial/ jdbc Security http://java.sun.com/docs/books /tutorial/ security1.2 xxxiii xxxiv ABOUT THIS TUTORIAL How... http://java.sun.com/docs/books /tutorial/ security1.2 xxxiii xxxiv ABOUT THIS TUTORIAL How to Read This Tutorial The J2EE 1.4 platform is quite large, and this tutorial reflects this However, you don’t have to digest everything in it at once This tutorial opens with three introductory chapters, which you should read before proceeding to any specific technology area Chapter 1 covers the J2EE 1.4 platform architecture and APIs along with the Sun... complete Web services support, the J2EE 1.4 platform offers Web services interoperability The J2EE 1.4 platform contains major enhancements to the Java servlet and JavaServer Pages (JSP) technologies that are the foundation of the Web tier The tutorial also showcases two exciting new technologies, not required by the J2EE 1.4 platform, that simplify the task of building J2EE application user interfaces:... ABOUT THIS TUTORIAL Bank Application (Chapter 36) describes an application that employs Web application technologies and enterprise beans Finally, the appendixes contain auxiliary information helpful to the J2EE application developer along with a brief summary of the J2EE Connector architecture: • • • • Java encoding schemes (Appendix A) XML Standards (Appendix B) HTTP overview (Appendix C) J2EE Connector . . . . . . .xxxi About This Tutorial. . . . . . . . . . . . . . . . . . . . . . . . .xxxiii Who Should Use This Tutorial xxxiii Prerequisites xxxiii How to Read This Tutorial xxxiv About the Examples. 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. The J2EE 1.4 Tutorial Eric Armstrong Jennifer Ball Stephanie Bodoff Debbie Bode Carson Ian Evans Dale Green Kim

Ngày đăng: 18/04/2014, 10:21

Mục lục

  • About This Tutorial

    • Who Should Use This Tutorial

    • How to Read This Tutorial

    • About the Examples

      • Required Software

        • Tutorial Bundle

        • Tutorial Example Directory Structure

        • How to Print This Tutorial

        • Overview

          • Distributed Multitiered Applications

            • J2EE Components

            • J2EE Clients

              • Web Clients

              • The JavaBeans™ Component Architecture

              • J2EE Server Communications

              • Enterprise Information System Tier

              • J2EE Containers

                • Container Services

                • UDDI and ebXML Standard Formats

                • Development Roles

                  • J2EE Product Provider

                  • Application Component Provider

                    • Enterprise Bean Developer

                    • Application Deployer and Administrator

                    • Java Message Service API

                    • Java API for XML Processing

                    • Java API for XML-Based RPC

                    • SOAP with Attachments API for Java

                    • Java API for XML Registries

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan