[ Team LiB ] Previous Section Next Section

Web Applications Defined

Web applications were originally introduced in the Servlet 2.2 specification, and are currently defined as follows by the Servlet 2.3 specification:

“A Web application is a collection of servlets, HTML pages, classes, and other resources that make up a complete application on a Web server.”

In other terms, a Web application is usually the layer between the Web client and the business layer, and acts as a bridge between them by passing the user requests to the business components and the processed response to the Web client.

A typical Web application consists of one or more of the following components:

  • Servlets— Read the input and perform simple operations, such as login and logout

  • JavaServer Pages— Used as presentation components

  • Static resources— HTML pages, graphics, CSS and JavaScript files

  • Utility and helper classes— For example, might include JavaBeans that can be used in the JSPs

  • Libraries— For example, Java classes bundled together as a JAR file that make up the tag library that contains the custom JSP tags

  • Any client-related classes, such as applets

Apart from the preceding components, a Web application contains configuration files containing the metadata that describes the application.

The clients to Web-based applications are categorized as thin clients, as opposed to traditional application clients, which are characterized as fat clients. In a traditional application, such as a three-tier application framework, the client layer is responsible for user interaction as well as some of the application logic, which makes it fat. In a Web-based application, the client is driven from within a browser that manages the user interaction in a way similar to that of the fat clients, but the application logic is completely embedded in the server components that make up the Web applications defined earlier.

The Web client user interface is usually defined using HTML, variations of it (for example, DHTML), or an XML/XSL combination. There are clearly defined protocols for data exchange between the client layer and the Web application, depending on the server components serving the client requests. But the most popular and widely used protocol is the HTTP/HTTPS protocol. HTTPS is a secure flavor of HTTP protocol for information exchange between Web applications (for example, servlets and JSP) and Web clients. Before we look at some of the key elements of the Web application, let's look at the environment in which Web applications run.

Web Container

The J2EE platform provides the necessary infrastructure for servicing client requests. These client requests might come from traditional clients or from Web clients. An application server such as WebLogic Server, providing the J2EE infrastructure, has one or more of the specific runtime environments that form the core of the product. These runtime environments are responsible for providing the services necessary for the different J2EE components such as servlets and EJBs. These are called containers. The most important of them are the Web container for Web applications and the EJB container for Enterprise JavaBeans. Figure 6.1 gives an idea of what each of the runtime environments hosts and the type of client requests they handle.

Figure 6.1. Anatomy of an application server.


Let's look at the need for these containers and benefit they offer to the components running within their environment. One of the fundamental goals of the J2EE application server framework is to provide the basic operating environment for all applications running within it. In other words, a business application such as an airline reservation system should concentrate on providing the business functions necessary to run the business, such as reservation, cancellation, flight status, and so on. Such an application should not be worried about transaction and state management, resource pooling, and other services. These services are common to most business applications. The different containers that are bundled as part of the application server provide the operating environment. Now let's look at the basic services offered by the Web container that is the runtime environment for the Web applications.

Web Container Services

The Web container is the interface between the J2EE components, such as servlets, and the low-level, platform-dependent functionality that's needed for the execution of the business function embedded in the component. There are certain rules of engagement for the container to provide the services to these components. The components are bundled into a well-defined package as specified by the J2EE specification and deployed into the Web container. The package contains application code as well as J2EE and vendor-specific configuration files that describe the application. The configuration parameters that are described using the XML-based configuration files specify certain container settings for every Web component and also specify settings for the Web application in totality. In short, these container settings help configure the basic support provided by the J2EE server as needed by the Web application. The support includes providing services such as security, transaction, JNDI lookup, and external resource mapping, to name a few.

A host of configurable services makes the life of the application deployer much easier. In most cases, a Web application can be deployed to heterogeneous environments with changes only to the configuration. For example, a Web component might have relaxed security settings in the development environment, whereas this would have to change when it's rolled into a production environment. Alternatively, the requirements might include that the application allow for a certain level of access to database data in one production environment and another level of database access in another production environment. All these are possible without change in the underlying application code with the help of the configuration files and the basic services offered by the container.

Let's look at the some of benefits that the WebLogic Server offers for the Web container:

  • The WebLogic Server security model helps the application deployer to secure the Web component so that the application and system resources are available only for the authorized users.

  • In accordance with the J2EE specifications, WebLogic Server also provides a unified access to the naming and directory services that enable Web components to access other enterprise components, such as EJBs, through the JNDI APIs.

  • In addition to the configurable services, some of which we touched on, WebLogic Server also manages some non-configurable services such as servlet/JSP life cycle, access to the J2EE platform APIs related to all Web components, and so on.

Web Application Components

As mentioned earlier in the chapter, the components that make up a Web application include servlets, JavaServer Pages, and their associated libraries and classes; specifically, the JSP tag library, JavaBeans, and so on. Let's look at each of these components in detail:

  • Servlets— These are Java classes that interact with Web clients to access server-side applications and that also can generate dynamic pages, thereby serving as an efficient server-side functional extension.

  • JSP (JavaServer Pages)— It is the enabling technology that enables you to combine the power of static HTML with dynamically generated content. JSPs enable the embedding of Java code in regular HTML-based Web pages. Additionally, JSP specifications allow for defining custom tags driven by Java classes called as taglibs, thereby enabling the encapsulation of complex server-side logic into simple tags that can be used in the JSP pages.


    We'll have a detailed discussion of the development of each of the preceding elements in Part IV, “Using Web Technologies in WebLogic Applications.”

  • JavaBeans— An API standard defined for Java classes, JavaBeans is one of the key technologies used in JSP and forms a part of the Web application. This concept is covered in detail in Chapter 16, “JavaBeans and Model-View-Controller (MVC) Architecture.” For further information, look at http://java.sun.com/beans/docs/.

Web Application Configuration

Apart from one or more of the key components, a Web application contains configuration-related information in a set of XML files that describes the Web application. These configuration files contain entries that are used by the Web container to provide the configurable services needed by the application, such as security and so on.

  • Web.xml— This is the Web application deployment descriptor that describes the contents of the Web application defined by J2EE standard as part of the specifications.

  • Weblogic.xml— This configuration file contains WebLogic Server–specific elements that describe the Web applications.

The configuration elements of web.xml are governed by the DTD (http://java.sun.com/dtd/web-app_2_3.dtd) defined as part of the J2EE Servlet Specification (V 2.3). The elements defined in web.xml can be grouped into the following types:

  • Servlet definitions— Defines the logical name for the servlet/JSP that maps to the implementing class

  • Servlet/JSP mappings— Help the Web container to map Web client requests to the corresponding servlet by using a defined URL pattern.

  • JSP tag library definition.

  • ServletContext parameters— Initialization parameters.

  • Session configuration.

  • Default welcome page for the Web application. For example, index.html and index.htm.

  • Error pages for defined error code or exception types.

  • Security-related parameters.

  • Filters and filter mappings that define the filter resources and filters that must be applied for the request types, respectively.


Similar to web.xml, the configuration elements of weblogic.xml are controlled by the following DTD http://www.bea.com/servers/wls810/dtd/weblogic810-web-jar.dtd.

Some of the most important elements defined in weblogic.xml are

  • The session descriptor, which defines servlet session-related parameters such as URL rewriting and cookie parameters

  • The JSP descriptor, which defines the compile options for the JSP such as the compile command, flags, pre-compiler, and working directory

  • The security role assignment for the security options defined in web.xml

  • The reference descriptors that define the resources referenced in the Web application

Figure 6.2 summarizes the discussion in this section and also touches on the deployment descriptors that make up the Web application.

Figure 6.2. Web application and containers.


In Figure 6.2, Web Application-1 and Web Application-2 represent two distinct applications that may be based on functionality, for example. In an airline reservation system, one Web application could cater to administrative functions executed by supervisors and another Web application could be related to customer-centric functions such as reservations, and so forth. As you can see from Figure 6.2, Web components are building blocks of all Web applications. The supporting cast for these applications includes other Java classes and static documents that can be in HTML and JPG file formats.

    [ Team LiB ] Previous Section Next Section