| CONTENTS | PREV | NEXT | INDEX | J2EE BluePrints |
A component is an application-level software unit. In addition to JavaBeans components, which are part of the J2SE platform, the J2EE platform supports the following types of components: applets, application clients, Enterprise JavaBeansTM components, and Web components. Applets and application clients run on a client platform and EJB and Web components run on a server platform.
All J2EE components depend on the runtime support of a system-level entity called a container. Containers provide components with services such as life cycle management, security, deployment, and threading. Because containers manage these services, many component behaviors can be declaratively customized when the component is deployed in the container. For example, an Application Component Provider can specify an abstract name for a database that an Enterprise JavaBeans component needs to access and a Deployer will link that name with the information (such as a user name and password) needed to access the database in a given environment.
The following sections provide overviews of the different types of J2EE components and containers.
Applets and application clients are client components that execute in their own Java virtual machine. An applet container includes support for the applet programming model. A J2EE client may make use of the Java Plug-in to provide the required applet execution environment. An application client container provides access to the J2EE service (see Section 2.3) and communication (see Section 2.5) APIs. Applets and application clients are covered in Chapter 3.
A Web component is a software entity that provides a response to a request. A Web component typically generates the user interface for a Web-based application. The J2EE platform specifies two types of Web components: servlets and JavaServer PagesTM (JSP) pages. The following sections give an overview of Web components. Web components are discussed in detail in Chapter 4.
2.1.2.1 Servlets
A servlet is a program that extends the functionality of a Web server. Servlets receive a request from a client, dynamically generate the response (possibly querying databases to fulfill the request), and then send the response containing an HTML or XML document to the client.
A servlet developer uses the servlet API to:
2.1.2.2 JavaServer Pages Technology
The JavaServer Pages (JSP) technology provides an extensible way to generate dynamic content for a Web client. A JSP page is a text-based document that describes how to process a request to create a response. A JSP page contains:
- Template data to format the Web document. Typically the template data uses HTML or XML elements. Document designers can edit and work with these elements on the JSP page without affecting the dynamic content. This approach simplifies development because it separates presentation from dynamic content generation.
- JSP elements and scriptlets to generate the dynamic content in the Web document. Most JSP pages use JavaBeans and/or Enterprise JavaBeans components to perform the more complex processing required of the application. Standard JSP actions can access and instantiate beans, set or retrieve bean attributes, and download applets. JSP is extensible through the development of custom actions, which are encapsulated in tag libraries.
2.1.2.3 Web Component Containers
Web components are hosted by servlet containers, JSP containers, and Web containers. In addition to standard container services, a servlet container provides network services (by which requests and responses are sent), decodes requests, and formats responses. All servlet containers must support HTTP as a protocol for requests and responses, but may also support additional request-response protocols such as HTTPS. A JSP container provides the same services as a servlet container and an engine that interprets and processes a JSP page into a servlet. A Web container provides the same services as a JSP container and access to the J2EE service and communication APIs.
The Enterprise JavaBeans (EJB) architecture is a server-side technology for developing and deploying components containing the business logic of an enterprise application. Enterprise JavaBeans components, termed enterprise beans, are scalable, transactional, and multi-user secure. There are two types of enterprise beans: session beans and entity beans. The following sections give an overview of enterprise beans. Enterprise beans are discussed in detail in Chapter 5.
2.1.3.1 Session Beans
A session bean is created to provide some service on behalf of a client and usually exists only for the duration of a single client-server session. A session bean performs operations such as calculations or accessing a database for the client. While a session bean may be transactional, it is not recoverable should its container crash.
Session beans can be stateless or can maintain conversational state across methods and transactions. If they do maintain state, the EJB container manages this state if the object must be removed from memory. However, the session bean object itself must manage its own persistent data.
2.1.3.2 Entity Beans
An entity bean is a persistent object that represents data maintained in a data store; its focus is data-centric. An entity bean can manage its own persistence or it can delegate this function to its container. An entity bean can live as long as the data it represents.
An entity bean is identified by a primary key. If the container in which an entity bean is hosted crashes, the entity bean, its primary key, and any remote references survive the crash.
2.1.3.3 EJB Component Containers
Enterprise beans are hosted by an EJB container. In addition to standard container services, an EJB container provides a range of transaction and persistence services and access to the J2EE service and communication APIs.
The J2EE component types and their containers are illustrated in Figure 2.1.
Containers provide all application components with the J2SE platform APIs,
which include the Java IDL and JDBC 2.0 core enterprise APIs. Table
2.1 lists the Standard Extension APIs that are available in each type of
container. The J2EE platform APIs are described in Section
2.4 and Section 2.5.
|
API |
Applet |
Application Client |
Web |
EJB |
|
JDBC 2.0 Extension |
N |
Y |
Y |
Y |
|
JTA 1.0 |
N |
N |
Y |
Y |
|
JNDI 1.2 |
N |
Y |
Y |
Y |
|
Servlet 2.2 |
N |
N |
Y |
N |
|
JSP 1.1 |
N |
N |
Y |
N |
|
EJB 1.1 |
N |
Y1 |
Y2 |
Y |
|
RMI-IIOP 1.0 |
N |
Y |
Y |
Y |
|
JMS 1.0 |
N |
Y |
Y |
Y |
|
JavaMail 1.1 |
N |
N |
Y |
Y |
|
JAF 1.0 |
N |
N |
Y |
Y |
| 1
Application clients can only make use of the enterprise bean client APIs. 2Servlets and JSP pages can only make use of the enterprise bean client APIs. |