6.1 OC4J ComponentsOC4J consists of three components:
The servlet and EJB containers have access to a standard set of services provided by the J2EE architecture that are managed by the server. The following sections describe these components and the relationships among them. 6.1.1 Servlet ContainerA servlet is a server-side Java program that extends the functionality of the application server in which it resides. A servlet container is the server-managed environment for executing a Java servlet. J2EE defines both a generic servlet and an extension called an HTTP servlet . An HTTP servlet has all the generic servlet capabilities plus functionality specific to dealing with the HTTP protocol. HTTP servlets are the most common type of servlet used in a servlet container because HTTP is the most common application-level protocol used on the Internet today. When someone requests dynamic content from a Java application server such as OC4J using HTTP, the request is most likely serviced by an HTTP servlet. A servlet container manages the life cycle of a servlet as follows :
A servlet is very performant because the same loaded and initialized servlet, already in memory, is used for each request. A servlet container also provides a set of standard services to a servlet. A common example is access to data sources, which provide servlets with access to databases. Services are discussed in more depth later in this chapter. The Hypertext Markup Language (HTML) produced by servlets to provide content for a web browser is sent to the browser by calling an HTTP servlet method that streams output back to the browser. This mechanism implies that a programmer writes Java code to produce web content. Creating web content in this Java-centric fashion may be well suited to programmers, but not web designers. To enable web designers to create dynamic content, an alternate method of designing servlets was created that is HTML-, not Java-centric. This alternative is called JavaServer Pages, described in the next section. 6.1.2 JavaServer Pages TranslatorA JavaServer Pages translator parses a JSP file, typically composed of HTML and Java code snippets and/or tags, and creates a corresponding servlet. This servlet is then executed in the servlet container like any other servlet. The difference here is that the source code in a JSP file consists of HTML with embedded Java code instead of Java code with embedded HTML. JSP also offers a means of using other markup languages such as Wireless Markup Language (WML) for mobile devices or, better yet, XML. If XML is used, an XML technology called the eXtensible Stylesheet Language for Transformations (XSLT) translates the markup into a suitable format for the device on which it's used: HTML for a web browser or WML for a wireless device. See Chapter 10 for a discussion of XML and Chapter 14 for information about OracleAS Wireless. 6.1.3 Enterprise JavaBeans ContainerAn EJB container is a server-managed environment for executing EJBs. An EJB is a Java program that can be executed as a component in a distributed fashion. A client program, a servlet, or another EJB can remotely execute the methods in an EJB. An EJB can also be executed locally if it exists in the same application server as the calling servlet or EJB. The EJB container provides transaction, security, and persistence management, as well as access to other server services such as Data Sources. In the J2EE architecture, an EJB can isolate business logic, represent a persistent entity, or process asynchronous information feeds. Appropriately, there are three types of EJBs: session, entity, and message-driven.
Transactions can be container- or bean-managed:
In a similar fashion, security and persistence (as mentioned earlier) can be managed by the container or by the component. When the container is responsible for these services, the programmer declaratively specifies the appropriate parameters in a file called a deployment descriptor . Whether exposing its configuration using a deployment descriptor, or being self-managed , an EJB exists as an independent software component that can conceivably be mixed and matched with other components to build an application. 6.1.4 OC4J Component RelationshipsFigure 6-1 demonstrates the relationship between these three components and the services to which they have access:
Figure 6-1. OC4J component relationshipsOC4J provides access to the J2EE architecture's APIs and to Oracle's own value-added APIs by what it refers to as OC4J Services. These services are described in the next section. |