Assembling and Configuring Web Applications

 Previous Next Contents Index View as PDF  

Web Applications Basics

The following sections describe how to configure and deploy Web Applications:

 


Overview of Web Applications

A Web Application contains an application's resources, such as servlets, JavaServer Pages (JSPs), JSP tag libraries, and any static resources such as HTML pages and image files. A Web Application can also define links to outside resources such as Enterprise JavaBeans (EJBs). Web Applications deployed on WebLogic Server use a standard J2EE deployment descriptor file and a WebLogic-specific deployment descriptor file to define their resources and operating parameters.

JSPs and HTTP servlets can access all services and APIs available in WebLogic Server. These services include EJBs, database connections via Java Database Connectivity (JDBC), JavaMessaging Service (JMS), XML, and more.

A Web archive contains the files that make up a Web Application (WAR file). A WAR file is deployed as a unit on one or more WebLogic Servers.

A Web archive on WebLogic Server always includes the following files:

A Web archive may also include HTML/XML pages and supporting files such as image and multimedia files.

The WAR file can be deployed alone or packaged in an Enterprise Archive (EAR file) with other application components. If deployed alone, the archive must end with a .war extension. If deployed in an EAR file, the archive must end with an .ear extension. (Note: If you are deploying an entire directory, do not name the directory .ear, .war, .jar and so on.)

Servlets

Servlets are Java classes that execute in WebLogic Server, accept a request from a client, process it, and optionally return a response to the client. A GenericServlet is protocol independent and can be used in J2EE applications to implement services accessed from other Java classes. An HttpServlet extends GenericServlet with support for the HTTP protocol. An HttpServlet is most often used to generate dynamic Web pages in response to Web browser requests.

JavaServer Pages

JSP pages are Web pages coded with an extended HTML that makes it possible to embed Java code in a Web page. JSP pages can call custom Java classes, called taglibs, using HTML-like tags. The WebLogic JSP compiler, weblogic.jspc, translates JSP pages into servlets. WebLogic Server automatically compiles JSP pages if the servlet class file is not present or is older than the JSP source file.

You can also precompile JSP pages and package the servlet class in the Web Archive to avoid compiling in the server. Servlets and JSP pages may depend upon additional helper classes that must also be deployed with the Web Application.

Web Application Directory Structure

Web Applications use a standard directory structure defined in the J2EE specification, and can be deployed as a collection of files that use this directory structure (this type of deployment is called exploded directory format) or as an archived file called a WAR file. Deploying a Web Application in exploded directory format is recommended primarily for use while developing your application. Deploying a Web Application as a WAR file is recommended primarily for production environments.

Web Application components are assembled in a directory in order to stage the WAR file for the jar command. HTML pages, JSP pages, and the non-Java class files they reference are accessed beginning in the top level of the staging directory.

The XML descriptors, compiled Java classes and JSP taglibs are stored in a WEB-INF subdirectory at the top level of the staging directory. Java classes include servlets, helper classes and, if desired, precompiled JSP pages.

The entire directory, once staged, is bundled into a WAR file using the jar command. The WAR file can be deployed alone or packaged in an Enterprise Archive (EAR file) with other application components, including other Web Applications, EJB components, and WebLogic components.

JSP pages and HTTP servlets can access all services and APIs available in WebLogic Server. These services include EJBs, database connections through Java Database Connectivity (JDBC), JavaMessaging Service (JMS), XML, and more.

 


Main Steps to Create a Web Application

The following steps summarize the procedure for creating a Web Application. You may want to use developer tools included with WebLogic Server for creating and configuring Web Applications. For more information, see Web Application Developer Tools.

To create a Web Application:

  1. Create the HTML pages and JSPs that make up the Web interface of the Web application. Typically, Web designers create these parts of a Web application.

    See Programming WebLogic JSP

  2. Write the Java code for the servlets and the JSP taglibs referenced in JavaServer Pages (JSPs). Typically, Java programmers create these parts of a Web application.

    See Programming WebLogic HTTP Servlets.

  3. Compile the servlets into class files.

    See "Preparing to Compile" in Developing WebLogic Server J2EE Applications.

  4. Arrange the resources (servlets, JSPs, static files, and deployment descriptors) in the prescribed directory format. See Directory Structure.

  5. Create the Web Application deployment descriptor (web.xml) and place the descriptor in the WEB-INF directory of the Web Application. In this step you register servlets, define servlet initialization parameters, register JSP tag libraries, define security constraints, and define other Web Application parameters.

    See Writing the web.xml Deployment Descriptor, and WebLogic Builder.

    You can edit Web Application deployment descriptors using various methods (see Tools for Editing Deployment Descriptors)

  6. Create the WebLogic-specific deployment descriptor (weblogic.xml) and place the descriptor in the WEB-INF directory of the Web Application. In this step you define how WebLogic Server will define JSP properties, JNDI mappings, security role mappings, and HTTP session parameters.

    See Writing the WebLogic-Specific Deployment Descriptor (weblogic.xml), and WebLogic Builder.

    You can edit Web Application deployment descriptors using various methods (see Tools for Editing Deployment Descriptors)

  7. Archive the Web Application files into a WAR file. (During development you may find it more convenient to update individual components of your Web Application in exploded directory format.) Use this command from the root directory of your Web Application:
    jar cv0f myWebApp.war .

    This command creates a Web Application archive file called myWebApp.war.

  8. If you are deploying the Web Application as part of an enterprise application, bundle the WAR file into an Enterprise Application archive (EAR file). See Deploying Web Applications as Part of an Enterprise Application

  9. Deploy the Web Application or Enterprise Application on WebLogic Server. This final step configures your application to service requests on WebLogic Server. See Deploying Web Applications.

 


Directory Structure

Develop your Web Application within a specified directory structure so that it can be archived and deployed on WebLogic Server or another J2EE-compliant server. All servlets, classes, static files, and other resources belonging to a Web Application are organized under a directory hierarchy. The root of this hierarchy defines the document root of your Web Application. All files under this root directory can be served to the client, except for files under the special directory WEB-INF, located under the root directory. The name of your Web Application is used to resolve requests for components of the Web Application.

Place private files in the WEB-INF directory, under the root directory. All files under WEB-INF are private, and are not served to a client.

DefaultWebApp/

Place your static files, such as HTML files and JSP files in the directory that is the document root of your Web Application. In the default installation of WebLogic Server, this directory is called DefaultWebApp, under user_domains/mydomain/applications.

DefaultWebApp/WEB-INF/web.xml

The Web Application deployment descriptor that configures the Web Application.

DefaultWebApp/WEB-INF/weblogic.xml

The WebLogic-specific deployment descriptor file that defines how named resources in the web.xml file are mapped to resources residing elsewhere in WebLogic Server. This file is also used to define JSP and HTTP session attributes.

DefaultWebApp/WEB-INF/classes

Contains server-side classes such as HTTP servlets and utility classes.

DefaultWebApp/WEB-INF/lib

Contains JAR files used by the Web Application, including JSP tag libraries.

 


URLs and Web Applications

Construct the URL that a client uses to access a Web Application using the following pattern:

http://hoststring/ContextPath/servletPath/pathInfo

Where

hoststring

is either a host name that is mapped to a virtual host or hostname:portNumber.

ContextPath

is the context root of your Web Application, if one is specified in application.xml or weblogic.xml. If the context root is not specified, ContextPath is the name of the Web Application archive file (for example, myWebApp.war) or the name of the directory in which the Web Application was deployed.

servletPath

is a servlet that is mapped to the servletPath.

pathInfo

is the remaining portion of the URL, typically a file name.

If you are using virtual hosting, you can substitute the virtual host name for the hoststring portion of the URL.

For additional information, see How WebLogic Server Resolves HTTP Requests.

 


Web Application Developer Tools

BEA provides several tools you can use to help you create and configure Web Applications.

WebLogic Builder

WebLogic Builder is a graphical tool for assembling a J2EE application module, creating and editing its deployment descriptors, and deploying it to a WebLogic server.

WebLogic Builder provides a visual editing environment for editing an application's deployment descriptor XML files. You can view these XML files as you visually edit them in WebLogic Builder, but you won't need to make textual edits to the XML files.

Use WebLogic Builder to do the following development tasks:

See WebLogic Builder.

Ant Tasks to Create Skeleton Deployment Descriptors

You can use the WebLogic Ant utilities to create skeleton deployment descriptors. These utilities are Java classes shipped with your WebLogic Server distribution. The Ant task looks at a directory containing a Web Application and creates deployment descriptors based on the files it finds in the Web Application. Because the Ant utility does not have information about all desired configurations and mappings for your Web Application, the skeleton deployment descriptors the utility creates are incomplete. After the utility creates the skeleton deployment descriptors, you can use a text editor, an XML editor, or the Administration Console to edit the deployment descriptors and complete the configuration of your Web Application.

For more information on using Ant utilities to create deployment descriptors, see Packaging Web Applications.

Web Application Deployment Descriptor Editor

The WebLogic Server Administration Console has an integrated deployment descriptor editor. You must create at least a skeleton web.xml deployment descriptor before using this integrated editor.

For more information, see Writing Web Application Deployment Descriptors and Web Application Deployment Descriptor Editor Help.

BEA XML Editor

The BEA XML Editor can validate XML code according to a specified DTD or XML Schema. It can be used on Windows or Solaris machines and is downloadable from BEA's Dev2Dev Online.

 

Back to Top Previous Next