Download J2EE component

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Notes of J2EE Tutorial
Matt Tsai
Outline


















Chapter 1: Overview
Chapter 2: Understanding XML
Chapter 3: Getting Started with Web
Applications
Chapter 4: Java API for XML Processing
Chapter 5: Simple API for XML
Chapter 6: Document Object Model
Chapter 7: Extensible Stylesheet Language
Transformations
Chapter 8: Building Web Services with JAXRPC
Chapter 9: SOAP with Attachments API for
Java
Chapter 10: Java API for XML Registries
Chapter 11: Java Servlet Technology
Chapter 12: JavaServer Pages Technology
Chapter 13: JavaServer Pages Documents
Chapter 14: JavaServer Pages Standard Tag
Library
Chapter 15: Custom Tags in JSP Pages
Chapter 16: Scripting in JSP Pages
Chapter 17: JavaServer Faces Technology
Chapter 18: Using JavaServer Faces
Technology in JSP Pages


















Chapter 19: Developing with JavaServer
Faces Technology
Chapter 20: Creating Custom UI Components
Chapter 21: Configuring JavaServer Faces
Applications
Chapter 22: Internationalizing and Localizing
Web Applications
Chapter 23: Enterprise Beans
Chapter 24: Getting Started with Enterprise
Beans
Chapter 25: Session Bean Examples
Chapter 26: Bean-Managed Persistence
Examples
Chapter 27: Container-Managed Persistence
Examples
Chapter 28: A Message-Driven Bean
Example
Chapter 29: Enterprise JavaBeans Query
Language
Chapter 30: Transactions
Chapter 31: Resource Connections
Chapter 32: Security
Chapter 33: The Java Message Service API
Chapter 34: J2EE Examples Using the JMS
API
Chapter 35: The Coffee Break Application
Chapter 36: The Duke's Bank Application
2
Overview

The J2EE platform uses a distributed multitiered application model for enterprise
applications.

The J2EE application parts shown in Figure 1-1 are presented in J2EE Components.
• Client-tier components run on the client machine.
• Web-tier components run on the J2EE server.
• Business-tier components run on the J2EE server.
• Enterprise information system (EIS)-tier software runs on the EIS server.
3
Overview

J2EE applications are made up of components.

A J2EE component is a self-contained functional software unit that
is assembled into a J2EE application with its related classes and files
and that communicates with other components.

The J2EE specification defines the following J2EE components.
• Application clients and applets are components that run on the client.
• Java Servlet and JavaServer Pages (JSP ) technology components are Web
components that run on the server.
• Enterprise JavaBeans (EJB ) components (enterprise beans) are business
components that run on the server.

J2EE components are written in the Java programming language and
are compiled in the same way as any program in the language.
4
Overview

J2EE Clients
• Web Clients
• Applets
• Application Clients

J2EE Server Communications
5
Overview

Web Components

Business Components
6
Overview

J2EE Containers
• Container Services

Containers are the interface between a component and the low-level platformspecific functionality that supports the component. Before a Web, enterprise bean,
or application client component can be executed, it must be assembled into a J2EE
module and deployed into its container.

The assembly process involves specifying container settings for each component
in the J2EE application and for the J2EE application itself.

Container settings customize the underlying support provided by the J2EE server,
including services such as security, transaction management, Java Naming and
Directory Interface (JNDI) lookups, and remote connectivity.
• Container Types
7
Overview

Web service support
• Web services are Web-based enterprise applications that use open,
XML-based standards and transport protocols to exchange data
with calling clients.
• The J2EE platform provides the XML APIs and tools you need to
quickly design, develop, test, and deploy Web services and
clients that fully interoperate with other Web services and clients
running on Java-based or non-Java-based platforms.
8
Overview

A J2EE application is delivered in an Enterprise Archive (EAR) file,
a standard Java Archive (JAR) file with an .ear extension.

Using EAR files and modules makes it possible to assemble a
number of different J2EE applications using some of the same
components.

EAR File Structure
9
Overview

A J2EE module consists of one or more J2EE components for the same container
type and one component deployment descriptor of that type.

An enterprise bean module deployment descriptor, for example, declares
transaction attributes and security authorizations for an enterprise bean. A J2EE
module without an application deployment descriptor can be deployed as a standalone module.

The four types of J2EE modules are as follows:
• EJB modules, which contain class files for enterprise beans and an EJB deployment
descriptor. EJB modules are packaged as JAR files with a .jar extension.
• Web modules, which contain servlet class files, JSP files, supporting class files, GIF
and HTML files, and a Web application deployment descriptor. Web modules are
packaged as JAR files with a .war (Web archive) extension.
• Application client modules, which contain class files and an application client
deployment descriptor. Application client modules are packaged as JAR files with
a .jar extension.
• Resource adapter modules, which contain all Java interfaces, classes, native libraries,
and other documentation, along with the resource adapter deployment descriptor.
Together, these implement the Connector architecture (see J2EE Connector
Architecture) for a particular EIS. Resource adapter modules are packaged as JAR files
with an .rar (resource adapter archive) extension.
10
Overview

Development Roles
• J2EE Product Provider
• Tool Provider
• Application Component Provider



Enterprise Bean Developer
Web Component Developer
Application Client Developer
• Application Assembler
• Application Deployer and Administrator
11
Overview

J2EE Platform APIs
12
Overview

The Sun Java System Application Server Platform Edition
8 is a fully compliant implementation of the J2EE 1.4
platform.

The Application Server includes a number of J2EE
technologies and tools that are not part of the J2EE 1.4
platform but are provided as a convenience to the
developer.

The Application Server includes two user interface
technologies
• JavaServer Pages Standard Tag Library
• JavaServer Faces
13
Overview

Application Server Tools
14
Overview

Starting and Stopping the Application Server
• To start and stop the Application Server

asadmin start-domain --verbose domain1
• To stop the Application Server, open a terminal window or
command prompt and execute


asadmin stop-domain domain1
Starting the Admin Console
• To administer the Application Server and manage users,
resources, and J2EE applications, you use the Admin Console
tool

http://localhost:4848/asadmin/
15
Understanding XML

XML is a text-based markup language that is fast
becoming the standard for data interchange on the Web.

After the XML declaration, the document prolog can
include a DTD, which lets you specify the kinds of tags
that can be included in your XML document. In addition
to telling a validating parser which tags are valid and in
what arrangements, a DTD tells both validating and
nonvalidating parsers where text is expected, which lets
the parser determine whether the whitespace it sees is
significant or ignorable.
16
Getting Started with Web Applications

A Web application is a dynamic extension of a Web or
application server. There are two types of Web
applications:
• Presentation-oriented:
• Service-oriented:

Java Web Application Technologies
17
Getting Started with Web Applications

Web Application Life Cycle
• Develop the Web component code.
• Develop the Web application deployment descriptor.
• Compile the Web application components and helper classes
referenced by the components.
• Optionally package the application into a deployable unit.
• Deploy the application into a Web container.
• Access a URL that references the Web application.
18
Getting Started with Web Applications

In the J2EE architecture, Web components and static Web content files such as images are called Web
resources. A Web module is the smallest deployable and usable unit of Web resources. A J2EE Web
module corresponds to a Web application as defined in the Java Servlet specification.

The document root contains a subdirectory named /WEB-INF/, which contains the following files and
directories:
• web.xml: The Web application deployment descriptor
• Tag library descriptor files (see Tag Library Descriptors)
• classes: A directory that contains server-side classes: servlets, utility classes, and JavaBeans
components
• tags: A directory that contains tag files, which are implementations of tag libraries (see Tag File
Location)
• lib: A directory that contains JAR archives of libraries called by server-side classes
19
Java API for XML Processing

SAX APIs

The SAX Packages
20
Java API for XML Processing

DOM APIs

The DOM Packages
21
Java API for XML Processing

XSLT APIs

The XSLT Packages
22
Building Web Services with JAX-RPC

JAX-RPC stands for Java API for XML-based RPC. JAX-RPC is a
technology for building Web services and clients that use remote
procedure calls (RPC) and XML. Often used in a distributed clientserver model, an RPC mechanism enables clients to execute
procedures on other systems.

In JAX-RPC, a remote procedure call is represented by an XMLbased protocol such as SOAP. The SOAP specification defines the
envelope structure, encoding rules, and conventions for representing
remote procedure calls and responses. These calls and responses are
transmitted as SOAP messages (XML files) over HTTP.

Although SOAP messages are complex, the JAX-RPC API hides
this complexity from the application developer.
23
Building Web Services with JAX-RPC

Communication Between a JAX-RPC Web Service and a Client

These are the basic steps for creating the Web service and client:
•
•
•
•
•
•
•
•
•
Code the SEI and implementation class and interface configuration file.
Compile the SEI and implementation class.
Use wscompile to generate the files required to deploy the service.
Use deploytool to package the files into a WAR file.
Deploy the WAR file. The tie classes (which are used to communicate with clients) are
generated by the Application Server during deployment.
Code the client class and WSDL configuration file.
Use wscompile to generate and compile the stub files.
Compile the client class.
Run the client.
24
Building Web Services with JAX-RPC

Coding the Service Endpoint Interface and
Implementation Class
25
SOAP with Attachments API for Java
26
Java API for XML Registries
27
Java Servlet Technology

A servlet is a Java programming language class that is used to
extend the capabilities of servers that host applications access via a
request-response programming model. Although servlets can
respond to any type of request, they are commonly used to extend
the applications hosted by Web servers. For such applications, Java
Servlet technology defines HTTP-specific servlet classes.

The javax.servlet and javax.servlet.http packages provide interfaces
and classes for writing servlets. All servlets must implement the
Servlet interface, which defines life-cycle methods. When
implementing a generic service, you can use or extend the
GenericServlet class provided with the Java Servlet API. The
HttpServlet class provides methods, such as doGet and doPost, for
handling HTTP-specific services.
28
JavaServer Pages Technology

JavaServer Pages (JSP) technology allows you to easily
create Web content that has both static and dynamic
components. JSP technology makes available all the
dynamic capabilities of Java Servlet technology but
provides a more natural approach to creating static content.
The
29
JSF

JavaServer Faces Standard Request-Response Life Cycle
30
Enterprise Bean

Structure of an Enterprise Bean JAR
31
Enterprise Bean

Life Cycle of a Stateful Session Bean

Life Cycle of a Stateless Session Bean
32
Enterprise Bean

Life Cycle of an Entity Bean

Life Cycle of a Message-Driven Bean
33
J2EE Connector Architecture

Resource Adapter Contracts

Resource Adapter Module Structure
34
The Coffee Break Application

Coffee Break Application Flow
35
The Duke's Bank Application

Duke's Bank Application
36