The Java EE 5 Tutorial 2nd Ed Edition Eric Jendrock All Chapter Instant Download
The Java EE 5 Tutorial 2nd Ed Edition Eric Jendrock All Chapter Instant Download
com
https://ebookfinal.com/download/the-java-ee-5-tutorial-2nd-
ed-edition-eric-jendrock/
OR CLICK BUTTON
DOWNLOAD EBOOK
https://ebookfinal.com/download/java-ee-5-development-using-glassfish-
application-server-1st-ed-edition-david-r-heffelfinger/
ebookfinal.com
https://ebookfinal.com/download/java-ee-development-with-eclipse-2nd-
edition-ram-kulkarni/
ebookfinal.com
https://ebookfinal.com/download/java-ee-6-pocket-guide-1st-edition-
arun-gupta/
ebookfinal.com
https://ebookfinal.com/download/beginning-ejb-3-java-ee-7-edition-
jonathan-wetherbee/
ebookfinal.com
Java EE 7 Development with NetBeans 8 3rd Edition David R.
Heffelfinger
https://ebookfinal.com/download/java-ee-7-development-with-
netbeans-8-3rd-edition-david-r-heffelfinger/
ebookfinal.com
https://ebookfinal.com/download/java-ee-7-recipes-a-problem-solution-
approach-1st-edition-josh-juneau-auth/
ebookfinal.com
https://ebookfinal.com/download/java-1-5-tiger-a-developer-s-
notebook-1st-ed-edition-david-flanagan/
ebookfinal.com
https://ebookfinal.com/download/java-in-a-nutshell-2nd-ed-edition-
david-flanagan/
ebookfinal.com
https://ebookfinal.com/download/java-concepts-compatible-with-
java-5-6-and-7-6th-edition-cay-s-horstmann/
ebookfinal.com
The Java™ EE 5
Tutorial
Jennifer Ball
Debbie Bode Carson
Ian Evans
Kim Haase
Eric Jendrock
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.
Chapter 1: Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Java EE Application Model 2
Distributed Multitiered Applications 3
Security 4
Java EE Components 5
Java EE Clients 5
Web Components 7
Business Components 8
Enterprise Information System Tier 9
Java EE Containers 9
Container Services 10
Container Types 11
Web Services Support 12
XML 12
SOAP Transport Protocol 13
WSDL Standard Format 13
UDDI and ebXML Standard Formats 14
Java EE Application Assembly and Deployment 14
Packaging Applications 14
iii
iv CONTENTS
Development Roles 16
Java EE Product Provider 16
Tool Provider 17
Application Component Provider 17
Application Assembler 18
Application Deployer and Administrator 18
Java EE 5 APIs 19
Enterprise JavaBeans Technology 20
Java Servlet Technology 20
JavaServer Pages Technology 20
JavaServer Pages Standard Tag Library 20
JavaServer Faces 21
Java Message Service API 21
Java Transaction API 22
JavaMail API 22
JavaBeans Activation Framework 22
Java API for XML Processing 22
Java API for XML Web Services (JAX-WS) 23
Java Architecture for XML Binding (JAXB) 23
SOAP with Attachments API for Java 23
Java API for XML Registries 24
J2EE Connector Architecture 24
Java Database Connectivity API 24
Java Persistence API 25
Java Naming and Directory Interface 25
Java Authentication and Authorization Service 26
Simplified Systems Integration 26
Sun Java System Application Server Platform Edition 9 27
Tools 27
Starting and Stopping the Application Server 28
Starting the Admin Console 29
Starting and Stopping the Java DB Database Server 30
Debugging Java EE Applications 30
Accessing a Session 86
Associating Objects with a Session 86
Session Management 87
Session Tracking 88
Finalizing a Servlet 89
Tracking Service Requests 89
Notifying Methods to Shut Down 90
Creating Polite Long-Running Methods 91
Further Information 92
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1181
About This Tutorial
Prerequisites
Before proceeding with this tutorial you should have a good knowledge of the
Java programming language. A good way to get to that point is to work through
all the basic and some of the specialized trails 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.
Trail URL
JDBC http://java.sun.com/docs/books/tutorial/jdbc
Security http://java.sun.com/docs/books/tutorial/security1.2
xxvii
xxviii
After you have become familiar with some of the technology areas, you are
ready to tackle the case studies, which tie together several of the technologies
discussed in the tutorial. The Coffee Break Application (Chapter 37) describes
an application that uses the web application and web services APIs. The Duke’s
xxx
Bank Application (Chapter 38) describes an application that employs web appli-
cation technologies, enterprise beans, and the Java Persistence API.
Finally, the appendix contains auxiliary information helpful to the Java EE 5
application developer:
• Java encoding schemes (Appendix A)
Required Software
The following software is required to run the examples.
Tutorial Bundle
The tutorial example source is contained in the tutorial bundle. If you are view-
ing this online, you need to click on the “Download” link at the top of any page.
After you have installed the tutorial bundle, the example source code is in the
<INSTALL>/javaee5tutorial/examples/ directory, with subdirectories for
each of the technologies discussed in the tutorial.
Application Server
The Sun Java System Application Server Platform Edition 9 is targeted as the
build and runtime environment for the tutorial examples. To build, deploy, and
run the examples, you need a copy of the Application Server and Java 2 Plat-
form, Standard Edition 5.0 (J2SE 5.0). If you already have a copy of the J2SE
SDK, you can download the Application Server from:
http://java.sun.com/javaee/downloads/index.html
You can also download the Java EE 5 SDK—which contains the Application
Server and the J2SE SDK—from the same site.
xxxi
Apache Ant
Ant is a Java technology-based build tool developed by the Apache Software
Foundation (http://ant.apache.org), and is used to build, package, and
deploy the tutorial examples. Ant is included with the Application Server. To use
the ant command-line tool add <JAVAEE_HOME>/lib/ant/bin to your PATH
environment variable.
Registry Server
You need a registry server to run the examples discussed in Chapter 19. Instruc-
tions for obtaining and setting up a registry server are provided in Chapter 19.
Note: On Windows, you must escape any backslashes in the javaee.home property
with another backslash or use forward slashes as a path separator. So, if your Appli-
cation Server installation is C:\Sun\AppServer, you must set javaee.home as fol-
lows:
javaee.home = C:\\Sun\\AppServer
or
javaee.home=C:/Sun/AppServer
dist subdirectory, which holds the packaged module file; and a client-jar
directory, which holds the retrieved application client JAR.
Further Information
This tutorial includes the basic information that you need to deploy applications
on and administer the Application Server.
See the Sun Java™ System Application Server Platform Edition 9 Developer’s
Guide at http://docs.sun.com/app/docs/doc/819-3659 for information
about developer features of the Application Server.
See the Sun Java™ System Application Server Platform Edition 9 Administra-
tion Guide at http://docs.sun.com/app/docs/doc/819-3658 for information
about administering the Application Server.
For information about the Java DB database included with the Application
Server see the Apache web site at http://db.apache.org/derby.
Typographical Conventions
Table 2 lists the typographical conventions used in this tutorial.
Feedback
To send comments, broken link reports, errors, suggestions, and questions about
this tutorial to the tutorial team, please use the feedback form at
http://java.sun.com/javaee/5/docs/tutorial/information/sendus-
mail.html.
xxxvi
1
Overview
The Java™ Persistence API is new to the Java EE 5 platform. The Java Persis-
tence API provides an object/relational mapping for managing relational data in
enterprise beans, web components, and application clients. It can also be used in
Java SE applications, outside of the Java EE environment.
This tutorial uses examples to describe the features and functionalities available
in the Java EE 5 platform for developing enterprise applications. Whether you
are a new or experienced Enterprise developer, you should find the examples and
accompanying text a valuable and accessible knowledge base for creating your
own solutions.
If you are new to Java EE enterprise application development, this chapter is a
good place to start. Here you will review development basics, learn about the
Java EE architecture and APIs, become acquainted with important terms and
concepts, and find out how to approach Java EE application programming,
assembly, and deployment.
Security
While other enterprise application models require platform-specific security
measures in each application, the Java EE security environment enables security
constraints to be defined at deployment time. The Java EE platform makes appli-
cations portable to a wide variety of security implementations by shielding appli-
cation developers from the complexity of implementing security features.
The Java EE platform provides standard declarative access control rules that are
defined by the developer and interpreted when the application is deployed on the
server. Java EE also provides standard login mechanisms so application develop-
ers do not have to implement these mechanisms in their applications. The same
application works in a variety of different security environments without chang-
ing the source code.
JAVA EE COMPONENTS 5
Java EE Components
Java EE applications are made up of components. A Java EE component is a
self-contained functional software unit that is assembled into a Java EE applica-
tion with its related classes and files and that communicates with other compo-
nents. The Java EE specification defines the following Java EE components:
• Application clients and applets are components that run on the client.
• Java Servlet, JavaServer Faces, and JavaServer Pages™ (JSP™) technol-
ogy components are web components that run on the server.
• Enterprise JavaBeans™ (EJB™) components (enterprise beans) are busi-
ness components that run on the server.
Java EE components are written in the Java programming language and are com-
piled in the same way as any program in the language. The difference between
Java EE components and “standard” Java classes is that Java EE components are
assembled into a Java EE application, are verified to be well formed and in com-
pliance with the Java EE specification, and are deployed to production, where
they are run and managed by the Java EE server.
Java EE Clients
A Java EE client can be a web client or an application client.
Web Clients
A web client consists of two parts: (1) dynamic web pages containing various
types of markup language (HTML, XML, and so on), which are generated by
web components running in the web tier, and (2) a web browser, which renders
the pages received from the server.
A web client is sometimes called a thin client. Thin clients usually do not query
databases, execute complex business rules, or connect to legacy applications.
When you use a thin client, such heavyweight operations are off-loaded to enter-
prise beans executing on the Java EE server, where they can leverage the secu-
rity, speed, services, and reliability of Java EE server-side technologies.
6 OVERVIEW
Applets
A web page received from the web tier can include an embedded applet. An
applet is a small client application written in the Java programming language
that executes in the Java virtual machine installed in the web browser. However,
client systems will likely need the Java Plug-in and possibly a security policy file
in order for the applet to successfully execute in the web browser.
Web components are the preferred API for creating a web client program
because no plug-ins or security policy files are needed on the client systems.
Also, web components enable cleaner and more modular application design
because they provide a way to separate applications programming from web
page design. Personnel involved in web page design thus do not need to under-
stand Java programming language syntax to do their jobs.
Application Clients
An application client runs on a client machine and provides a way for users to
handle tasks that require a richer user interface than can be provided by a markup
language. It typically has a graphical user interface (GUI) created from the
Swing or the Abstract Window Toolkit (AWT) API, but a command-line inter-
face is certainly possible.
Application clients directly access enterprise beans running in the business tier.
However, if application requirements warrant it, an application client can open
an HTTP connection to establish communication with a servlet running in the
web tier. Application clients written in languages other than Java can interact
with Java EE 5 servers, enabling the Java EE 5 platform to interoperate with leg-
acy systems, clients, and non-Java languages.
Web Components
Java EE web components are either servlets or pages created using JSP technol-
ogy (JSP pages) and/or JavaServer Faces technology. Servlets are Java program-
ming language classes that dynamically process requests and construct
responses. JSP pages are text-based documents that execute as servlets but allow
8 OVERVIEW
Business Components
Business code, which is logic that solves or meets the needs of a particular busi-
ness domain such as banking, retail, or finance, is handled by enterprise beans
running in the business tier. Figure 1–4 shows how an enterprise bean receives
data from client programs, processes it (if necessary), and sends it to the enter-
prise information system tier for storage. An enterprise bean also retrieves data
from storage, processes it (if necessary), and sends it back to the client program.
Java EE Containers
Normally, thin-client multitiered applications are hard to write because they
involve many lines of intricate code to handle transaction and state management,
multithreading, resource pooling, and other complex low-level details. The com-
ponent-based and platform-independent Java EE architecture makes Java EE
applications easy to write because business logic is organized into reusable com-
ponents. In addition, the Java EE server provides underlying services in the form
of a container for every component type. Because you do not have to develop
10 OVERVIEW
these services yourself, you are free to concentrate on solving the business prob-
lem at hand.
Container Services
Containers are the interface between a component and the low-level platform-
specific functionality that supports the component. Before a web, enterprise
bean, or application client component can be executed, it must be assembled into
a Java EE module and deployed into its container.
The assembly process involves specifying container settings for each component
in the Java EE application and for the Java EE application itself. Container set-
tings customize the underlying support provided by the Java EE server, including
services such as security, transaction management, Java Naming and Directory
Interface™ (JNDI) lookups, and remote connectivity. Here are some of the high-
lights:
• The Java EE security model lets you configure a web component or enter-
prise bean so that system resources are accessed only by authorized users.
• The Java EE transaction model lets you specify relationships among meth-
ods that make up a single transaction so that all methods in one transaction
are treated as a single unit.
• JNDI lookup services provide a unified interface to multiple naming and
directory services in the enterprise so that application components can
access these services.
• The Java EE remote connectivity model manages low-level communica-
tions between clients and enterprise beans. After an enterprise bean is cre-
ated, a client invokes methods on it as if it were in the same virtual
machine.
Because the Java EE architecture provides configurable services, application
components within the same Java EE application can behave differently based
on where they are deployed. For example, an enterprise bean can have security
settings that allow it a certain level of access to database data in one production
environment and another level of database access in another production environ-
ment.
The container also manages nonconfigurable services such as enterprise bean
and servlet life cycles, database connection resource pooling, data persistence,
and access to the Java EE platform APIs (see section Java EE 5 APIs, page 19).
CONTAINER TYPES 11
Container Types
The deployment process installs Java EE application components in the Java EE
containers illustrated in Figure 1–5.
Java EE server
The runtime portion of a Java EE product. A Java EE server provides EJB
and web containers.
Enterprise JavaBeans (EJB) container
Manages the execution of enterprise beans for Java EE applications. Enter-
prise beans and their container run on the Java EE server.
Web container
Manages the execution of JSP page and servlet components for Java EE
applications. Web components and their container run on the Java EE server.
Application client container
Manages the execution of application client components. Application clients
and their container run on the client.
Applet container
Manages the execution of applets. Consists of a web browser and Java Plug-
in running on the client together.
12 OVERVIEW
XML
XML is a cross-platform, extensible, text-based standard for representing data.
When XML data is exchanged between parties, the parties are free to create their
own tags to describe the data, set up schemas to specify which tags can be used
in a particular kind of XML document, and use XML stylesheets to manage the
display and handling of the data.
For example, a web service can use XML and a schema to produce price lists,
and companies that receive the price lists and schema can have their own
SOAP TRANSPORT PROTOCOL 13
stylesheets to handle the data in a way that best suits their needs. Here are exam-
ples:
• One company might put XML pricing information through a program to
translate the XML to HTML so that it can post the price lists to its intranet.
• A partner company might put the XML pricing information through a tool
to create a marketing presentation.
• Another company might read the XML pricing information into an appli-
cation for processing.
Packaging Applications
A Java EE application is delivered in an Enterprise Archive (EAR) file, a stan-
dard Java Archive (JAR) file with an .ear extension. Using EAR files and mod-
ules makes it possible to assemble a number of different Java EE applications
using some of the same components. No extra coding is needed; it is only a mat-
ter of assembling (or packaging) various Java EE modules into Java EE EAR
files.
An EAR file (see Figure 1–6) contains Java EE modules and deployment
descriptors. A deployment descriptor is an XML document with an .xml exten-
sion that describes the deployment settings of an application, a module, or a
component. Because deployment descriptor information is declarative, it can be
changed without the need to modify the source code. At runtime, the Java EE
server reads the deployment descriptor and acts upon the application, module, or
component accordingly.
Exploring the Variety of Random
Documents with Different Content
remains social property. But another part is as means of living
consumed by the members of the association. It must therefore be
distributed among them. The nature of this distribution will change
according to the special nature of the organisation of production and
the corresponding grade of historical development of the producers.’
And then he goes on to assume that the share of each producer in
the means of living may be determined by his labour time. Labour
time will at once serve as measure of the share of each producer in
the common labour, and therefore also of his share in the portion of
the common product which is devoted to consumption.[5]
Another important indication by one who has full right to speak for
Marx is contained in Fr. Engels’ views regarding the State. After the
proletariat have seized political power and transformed the means of
production into State property, the State will cease to exist. In the
old societies the State was an organisation of the exploiting class for
the maintenance of the conditions of exploitation that suited it.
Officially the representatives of the whole society, the exploiting
class only represented itself. But when the State at last becomes the
real representative of the whole society it renders itself superfluous.
In a society which contains no subject class, from which class rule
and the anarchy of production and the collisions and excesses of the
struggle for individual existence have been removed, there is
nothing to repress, and no need for a repressing force like the State.
The first act wherein the State really appears as representative of
the entire society—the appropriation of the means of production in
the name of society—is also its last independent act as State. In
place of the government over persons, there will be an
administration of things and the control of productive processes. The
State is not abolished; it dies away.[6]
In effect, these two indications of opinion point to a condition of
society which is not fundamentally different from that contemplated
by the anarchist school. Both look forward to a period when men will
live in free associations, and when the administration of social affairs
will be conducted without the exercise of compulsion.
It will have been seen that what Marx and his school contemplate is
an economic revolution brought about in accordance with the natural
laws of historic evolution. But in order to understand the full import
of this revolution in the mind of Marx, we must remember that he
regards the economic order of society as the groundwork of the
same, determining all the other forms of social order. The entire
legal and political structure, as well as philosophy and religion, are
constituted and controlled in accordance with the economic basis.
This is in harmony with his method and his conception of the world,
which is the Hegelian reversed: ‘For Hegel the thought process,
which he transforms into an independent subject under the name
idea, is the creator of the real, which forms only its external
manifestation. With me, on the contrary, the ideal is nothing else
than the material transformed and translated in the human brain.’
His conception of the world is a frank and avowed materialism.
And to a world thus understood he applies the dialectic method of
investigation. Dialectic is a word current in the Hegelian and other
philosophies. It sounds rather out of place in a materialistic view of
the world. In the system of Marx it means that the business of
inquiry is to trace the connection and concatenation in the links that
make up the process of historic evolution, to investigate how one
stage succeeds another in the development of society, the facts and
forms of human life and history not being stable and stereotyped
things, but the ever-changing manifestations of the fluent and
unresting real, the course of which it is the duty of science to reveal.
Both Marx and Fr. Engels, moreover, are fond of expressing the
development of capitalism in the language of the well-known
Hegelian threefold process—thesis, antithesis, and synthesis. Private
property resting on a man’s own labour of the former times is the
thesis. The property resting on other men’s labour of the capitalistic
era is the negation of this individual property. The expropriation of
the capitalists by the proletariat is the negation of the negation, or
synthesis. But how far this use of the Hegelian terms is merely a
form of literary expression, or how far it is a survival in Marx of a
real belief in Hegelianism, it is not easy to determine.[7]
The whole position of the Marx school may be characterised as
evolutionary and revolutionary socialism, based on a materialistic
conception of the world and of human history. Socialism is a social
revolution determined by the laws of historic evolution—a revolution
which, changing the economic groundwork of society, will change
the whole structure.
It may now be convenient to sum up the socialism of the Marx
school under the following heads:—
THE INTERNATIONAL