Home > Store

Java  Web Services Tutorial, The

Register your product to gain access to bonus material or receive a coupon.

Java Web Services Tutorial, The


  • Sorry, this book is no longer in print.
Not for Sale


  • Copyright 2002
  • Edition: 1st
  • Book
  • ISBN-10: 0-201-76811-9
  • ISBN-13: 978-0-201-76811-4

The Java™ Web Services Tutorial is a comprehensive, example-driven, "roll up your sleeves and dive in" guide to building Web services applications with Java™ technology. This edition provides a head start on using the Java Web Services Developer Pack (WSDP) from Sun Microsystems. This complete, ready-to-use package includes a variety of technologies and tools required to build and deploy comprehensive Web services applications today.

Web services offer powerful new ways for enterprises to effectively communicate with each other using diverse computing hardware. This paradigm takes the Java platform's "Write Once, Run Anywhere™" capabilities to a new level by providing a completely portable data model. By supporting the latest standards for XML-based Web services, the Java APIs for XML make it easy to build Web services with minimal hand tweaking of data. This tutorial explains these APIs in detail and provides practical examples to reinforce your understanding of key concepts.

The accompanying CD-ROM includes:

  • Java API for XML Messaging (JAXM) 1.0 EA 1
  • Java API for XML Processing (JAXP) 1.2 EA 1 (with XML Schema support)
  • Java API for XML Registries (JAXR) 1.0 EA 1
  • Java API for XML-based RPC (JAX-RPC) 1.0 EA 1
  • JavaServer Pages™ Standard Tag Library (JSTL) 1.0 EA 3
  • Ant Build Tool 1.4.1
  • Java WSDP Registry Server 1.0 EA 1
  • Tomcat Java Servlet and JavaServer Pages container 4.1-dev
  • This package also includes instructions for deploying Web services applications on the Java 2 SDK, Enterprise Edition.


    Sample Content

    Online Sample Chapter

    An Introductory Tutorial on Web Services, Java and XML

    Table of Contents



    1. Introduction to Web Services.

    The Role of XML and the Java Platform.

    What Is XML?

    What Makes XML Portable?

    Overview of the Java APIs for XML.


    The SAX API.

    The DOM API.

    The XSLT API.


    Using JAX-RPC.


    Getting a Connection.

    Creating a Message.

    Populating a Message.

    Sending a Message.


    Using JAXR.

    Sample Scenario.



    2. Understanding XML.

    Introduction to XML.

    What Is XML?

    Why Is XML Important?

    How Can You Use XML?

    XML and Related Specs: Digesting the Alphabet Soup.

    Basic Standards.

    Schema Standards.

    Linking and Presentation Standards.

    Knowledge Standards.

    Standards That Build on XML.


    Designing an XML Data Structure.

    Saving Yourself Some Work.

    Attributes and Elements.

    Normalizing Data.

    Normalizing DTDs.

    3. Getting Started with Tomcat.

    Setting Up.

    Getting the Example Code.

    Checking the Environment Variables.

    Creating the Getting Started Application.

    The Converter Class.

    The Web Client.

    Building and Deploying the Getting Started Application Using Ant.

    Setting the CLASSPATH.

    Creating the Build File for Ant.

    Compiling the Source Files.

    Deploying the Application.

    Running the Getting Started Application.

    Starting Tomcat.

    Running the Web Client.

    Shutting Down Tomcat.

    Modifying the Application.

    Modifying a Class File.

    Modifying the Web Client.

    Reloading the Application.

    Common Problems and Their Solutions.

    Cannot Start the Tomcat Server.

    Compilation Errors.

    Deployment Errors.

    4. Java API for XML Processing.

    The JAXP APIs.

    An Overview of the Packages.

    The Simple API for XML (SAX) APIs.

    The SAX Packages.

    The Document Object Model (DOM) APIs.

    The DOM Packages.

    The XML Stylesheet Language for Transformation (XSLT) APIs.

    The XSLT Packages.

    Compiling and Running the Programs.

    Where Do You Go from Here?

    5. Simple API for XML.

    Writing a Simple XML File.

    Creating the File.

    Writing the Declaration.

    Adding a Comment.

    Defining the Root Element.

    Adding Nested Elements.

    Adding HTML-Style Text.

    Adding an Empty Element.

    The Finished Product.

    Echoing an XML File with the SAX Parser.

    Creating the Skeleton.

    Importing Classes.

    Setting up for I/O.

    Implementing the ContentHandler Interface.

    Setting up the Parser.

    Writing the Output.

    Spacing the Output.

    Handling Content Events.

    Compiling and Running the Program.

    Checking the Output.

    Identifying the Events.

    Compressing the Output.

    Inspecting the Output.

    Documents and Data.

    Adding Additional Event Handlers.

    Identifying the Document's Location.

    Handling Processing Instructions.


    Handling Errors with the Nonvalidating Parser.

    Substituting and Inserting Text.

    Handling Special Characters.

    Using an Entity Reference in an XML Document.

    Handling Text with XML-Style Syntax.

    Handling CDATA and Other Characters.

    Creating a Document Type Definition (DTD).

    Basic DTD Definitions.

    Defining Text and Nested Elements.

    Limitations of DTDs.

    Special Element Values in the DTD.

    Referencing the DTD.

    DTD's Effect on the Nonvalidating Parser.

    Tracking Ignorable Whitespace.


    Documents and Data.

    Empty Elements, Revisited.

    Defining Attributes and Entities in the DTD.

    Defining Attributes in the DTD.

    Defining Entities in the DTD.

    Echoing the Entity References.

    Additional Useful Entities.

    Referencing External Entities.

    Echoing the External Entity.

    Summarizing Entities.

    Referencing Binary Entities.

    Using a MIME Data Type.

    The Alternative: Using Entity References.

    Using the Validating Parser.

    Configuring the Factory.

    Changing the Environment Variable.

    Experimenting with Validation Errors.

    Error Handling in the Validating Parser.

    Defining Parameter Entities and Conditional Sections.

    Creating and Referencing a Parameter Entity.

    Conditional Sections.

    Parsing the Parameterized DTD.

    DTD Warnings.

    Handling Lexical Events.

    How the LexicalHandler Works.

    Working with a LexicalHandler.

    Using the DTDHandler and EntityResolver.

    The DTDHandler API.

    The EntityResolver API.

    6. Document Object Model.

    Reading XML Data into a DOM.

    Creating the Program.

    Additional Information.

    Looking Ahead.

    Displaying a DOM Hierarchy.

    Echoing Tree Nodes.

    Convert DomEcho to a GUI App.

    Create Adapters to Display the DOM in a Jtree.

    Finishing Up.

    Examining the Structure of a DOM.

    Displaying A Simple Tree.

    Displaying a More Complex Tree.

    Finishing Up.

    Constructing a User-Friendly JTree from a DOM.

    Compressing the Tree View.

    Acting on Tree Selections.

    Handling Modifications.

    Finishing Up.

    Creating and Manipulating a DOM.

    Obtaining a DOM from the Factory.

    Normalizing the DOM.

    Other Operations.

    Finishing Up.

    Using Namespaces.

    Defining a Namespace.

    Referencing a Namespace.

    Defining a Namespace Prefix.

    7. XML Stylesheet Language for Transformations.

    Introducing XSLT and XPath.

    The XSLT Packages.

    How XPath Works.


    Writing Out a DOM as an XML File.

    Reading the XML.

    Creating a Transformer.

    Writing the XML.

    Writing Out a Subtree of the DOM.


    Generating XML from an Arbitrary Data Structure.

    Creating a Simple File.

    Creating a Simple Parser.

    Modifying the Parser to Generate SAX Events.

    Using the Parser as a SAXSource.

    Doing the Conversion.

    Transforming XML Data with XSLT.

    Defining an Ultra-Simple Article Document Type.

    Creating a Test Document.

    Writing an XSLT Transform.

    Processing the Basic Structure Elements.

    Writing the Basic Program.

    Trimming the Whitespace.

    Processing the Remaining Structure Elements.

    Process Inline (Content) Elements.

    Printing the HTML.

    What Else Can XSLT Do?

    Concatenating XSLT Transformations with a Filter Chain.

    Writing the Program.

    Understanding How it Works.

    Testing the Program.


    8. Java API for XML Messaging.

    Overview of JAXM.



    Messaging Providers.

    Running the Samples.

    The Sample Programs.

    The Provider Administration Tool.


    Client without a Messaging Provider.

    Client with a Messaging Provider.

    Adding Attachments.

    Code Examples.



    9. Java API for XML-based RPC.

    What is JAX-RPC?

    A Simple Example: HelloWorld.

    HelloWorld at Runtime.

    HelloWorld Files.

    Overview of Steps.

    Setting Up.

    Coding the Service Definition Interface and Implementation Class.

    Compiling the Service Definition Code.

    Creating the Configuration File.

    Generating the Stubs and Ties.

    Creating the Deployment Descriptor.

    Packaging the Service Definition.

    Deploying the Service Definition.

    Coding the Client.

    Compiling the Client Code.

    Running the Client.

    The Dynamic Invocation Interface.

    When to Use DII.

    A DII Client Example.

    10. Java API for XML Registries.

    Overview of JAXR.

    What is a Registry?

    What Is JAXR?

    JAXR Architecture.

    Implementing a JAXR Client.

    Establishing a Connection.

    Querying a Registry.

    Managing Registry Data.

    Running the Client Examples.

    Using the Registry Browser.

    Querying a Registry.

    Managing Registry Data.

    11. The Java WSDP Registry Server.

    Setting Up the Registry Server.

    Using the JAXR Registry Browser with the Registry Server.

    Adding Organizations.

    Querying the Registry.

    Using the Command Line Client Scripts with the Registry Server.

    Using the JAXR API to Access the Registry Server.

    Using the Indri Tool to Access the Registry Server Database.

    12. Web Applications.

    Web Application Life Cycle.

    Web Application Archives,

    Creating a WAR File.

    Web Application Deployment Descriptors.


    Context Parameters.

    Filter Mappings.

    Event Listeners.

    Alias Paths.

    Error Mappings.

    References to Environment Entries, Resource Environment Entries, or Resources.

    Deploying Web Applications.

    Specifying the Web Application Context.


    Running Web Applications.

    Updating Web Applications.

    Internationalizing and Localizing Web Applications.

    Accessing Databases from Web Applications.

    The Examples.

    Downloading and Starting the Database Server.

    Populating the Database.

    Configuring the Web Application to Use the Database.

    Configuring the Server to Recognize the Database.

    13. Java Servlet Technology.

    What is a Servlet?

    The Example Servlets.


    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 Response.

    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.

    Accessing a Session.

    Associating Attributes with a Session.

    Session Management.

    Session Tracking.

    Finalizing a Servlet.

    Tracking Service Requests.

    Notifying Methods to Shut Down.

    Creating Polite Long-Running Methods.

    14. JavaServer Pages Technology.

    What is a JSP Page?

    The Example JSP Pages.

    The Life Cycle of a JSP Page.

    Translation and Compilation.


    Initializing and Finalizing a JSP Page.

    Creating Static Content.

    Creating Dynamic Content.

    Using Objects Within JSP Pages.

    JSP Scripting Elements.

    Including Content in a JSP Page.

    Transferring Control to Another Web Component.

    Param Element.

    Including an Applet.

    Extending the JSP Language.

    15. JavaBeans Components in JSP Pages.

    JavaBeans Component Design Conventions.

    Why Use a JavaBeans Component?

    Creating and Using a JavaBeans Component.

    Setting JavaBeans Component Properties.

    Retrieving JavaBeans Component Properties.

    16. Custom Tags in JSP Pages.

    What is a Custom Tag?

    The Example JSP Pages.

    Using Tags.

    Declaring Tag Libraries.

    Making the Tag Library Implementation Available.

    Types of Tags.

    Defining Tags.

    Tag Handlers.

    Tag Library Descriptors.

    Simple Tags.

    Tags with Attributes.

    Tags with Bodies.

    Tags That Define Scripting Variables.

    Cooperating Tags.


    An Iteration Tag.

    A Template Tag Library.

    How Is a Tag Handler Invoked?

    17. JavaServer Pages Standard Tag Library.

    The Example JSP Pages.

    Using JSTL.

    Expression Language Support.

    Twin Libraries.

    Specifying an Expression Language Evaluator.

    Simplest Possible Expression Language (SPEL).

    Tag Collaboration.

    Core Tags.

    Expression Tags.

    Flow Control Tags.

    Import Tags.

    XML Tags.

    Core Tags.

    Flow Control Tags.

    Transformation Tags.

    Internationalization Tags.

    Messaging Tags.

    Formatting Tags.

    SQL Tags.

    Query Tag Result-Related Interfaces.

    18. The xrpcc Tool.


    Configuration File.

    Starting with RMI Interfaces.

    Starting with a WSDL Document.

    Specifying the Type Mapping.

    19. HTTP Overview.

    HTTP Requests.

    HTTP Responses.

    Appendix: Java Encoding Schemes.

    About the Authors.

    Index. 0201768119T03262002


    The Java™ Web Services Tutorial is a beginner's guide to developing Web services and Web applications using the Java Web Services Developer Pack (Java WSDP). The Java WSDP is an all-in-one download containing key technologies to simplify building of Web services using the Java 2 Platform. The technologies available on the Java WSDP are:

    • Java Servlets
    • JavaServer Pages (JSP)
    • JSP Standard Tag Library (JSTL)
    • Java XML Pack, which includes:
      • Java API for XML Messaging (JAXM)
      • Java API for XML Processing (JAXP)
      • Java API for XML Registries (JAXR)
      • Java API for XML-based RPC (JAX-RPC)

    To provide a development and deployment environment, the Java WSDP includes the:

    • Tomcat servlet and JSP container
    • Ant build tool
    • Java WSDP Registry Server

    Here we cover all the things you need to know to make the best use of The Java™ Web Services Tutorial.

    Who Should Use This Tutorial

    This tutorial is intended for programmers interested in developing and deploying Web services and Web applications on the Java WSDP.

    About the Examples

    This tutorial includes many complete, working examples.

    Prerequisites for the Examples

    To understand the examples you will need a good knowledge of the Java programming language, SQL, and relational database concepts. The following topics in the Java Tutorial are particularly relevant:

    Running the Examples

    This section tells you everything you need to know to obtain, build, deploy, and run the examples.

    Required Software

    If you are viewing this online, you need to download The Java Web™ Services Tutorial from:


    Once you have installed the tutorial bundle, the example source code is in the <JWSDP_HOME>/docs/tutorial/examples directory, with subdirectories for each of the technologies included in the pack.

    This tutorial documents the Java WSDP EA1. To build, deploy, and run the examples you need a copy of the Java WSDP and the Java 2 Platform, Standard Edition (J2SE™) SDK 1.3.1 or 1.4. You can download the Java WSDP from:


    the J2SE 1.3.1 SDK from:


    or the J2SE 1.4 SDK from:

    Building the Examples

    Most of the examples are distributed with a configuration file for version 1.4.1 of ant, a portable build tool contained in the Java WSDP. Directions for building the examples are provided in each chapter.

    Deploying the Examples

    Most of the Java WSDP examples run on Tomcat. Before you can run an example you must first deploy it on Tomcat. To deploy an application execute ant deploy. The deploy task usually copies some files into the <JWSDP_HOME>/webapps directory. Some things you need to keep in mind:

    • For this release of the Java WSDP you must be running Tomcat on the same machine that you are developing on.
    • The first time an application is deployed you must start or restart Tomcat (see next section). Thereafter, when you modify an application, you can build, deploy, and then reload the example, as described in the next section.
    Running Tomcat

    You run Tomcat by executing the startup script in a terminal window.

    Reloading the Examples

    You reload an application with the command:

    This command invokes the manager Web application. Before you can use this application you must add your user name and password combination and associate the role name manager with it to <JWSDP_HOME>/conf/tomcat-users.xml, which can be edited with any text editor. This file contains an element <user> for each individual user, which might look something like this:

    <user name="adeveloper" password="secret" roles="manager" />

    The Tomcat reference documentation distributed with the Java WSDP contains information about the manager application.

    Related Information

    For further information on the technologies discussed in this tutorial see the reference documentation contained in the Java WSDP (<JWSDP_HOME>/docs/index.html). References to individual technology homes listed in some chapters map as follows:

    • JAXM-HOME to JWSDP_HOME/docs/jaxm/index.html
    • JAXP-HOME to JWSDP_HOME/docs/jaxp/index.html
    • JAXR-HOME to JWSDP_HOME/docs/jaxr/index.html
    • JAXRPC-HOME to JWSDP_HOME/docs/jaxrpc/index.html

    • 0201768119P03262002


    Submit Errata

    More Information

    Unlimited one-month access with your purchase
    Free Safari Membership