bea.com | products | dev2dev | support | askBEA
 Download Docs   Site Map   Glossary 
Search

Developing Web Applications for WebLogic Server

 Previous Next Contents Index View as PDF  

Web Applications Basics

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

 


How to Use This Book

As you develop and deploy your Web Application, you will use this guide in conjunction with Developing WebLogic Server Applications and Deploying WebLogic Server Applications. These two guides provide detailed procedures and are your primary sources for creating, packaging, and deploying J2EE applications, including Web Applications, to WebLogic Server. Refer to this guide, Developing Web Applications for WebLogic Server, to supplement that information with procedures and reference material that are specific to 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 (WAR file) contains the files that make up a Web Application (WAR file). A WAR file is deployed as a unit on one or more WebLogic Server instances.

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

A Web archive may also include HTML or 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 a directory in exploded format (not archived), do not name the directory .ear, .jar, and so on. For more information on archived format, see Web Application Directory Structure

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.

Java Server Pages

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

You can also precompile JSPs and package the servlet class in the Web Archive to avoid compiling in the server. Servlets and JSPs may require additional helper classes to be deployed with the Web Application.

Web Application Directory Structure

Web Applications use a standard directory structure defined in the J2EE specification. You can deploy a Web application as a collection of files that use this directory structure, known as 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.

Clients can generally browse any location in a Web application with the exception of the WEB-INF directory. The WEB-INF directory contains the deployment descriptors for the Web application (web.xmland weblogic.xml) and two subdirectories for storing compiled Java classes and library JAR files. These subdirectories are respectively named classes and lib. JSP taglibs are stored in the WEB-INF directory at the top level of the staging directory. The Java classes include servlets, helper classes and, if desired, precompiled JSPs.

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 Server 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.

    For detailed information about creating JSPs, 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.

    For detailed information about creating servlets, see Programming WebLogic HTTP Servlets and Programming WebLogic JSP

  3. Compile the servlets into class files.

    For detailed information about compiling java code, refer to the section "Developing WebLogic Server Applications" in Developing WebLogic Server Applications.

    For instructions on using the WebLogic Server appc compiler, see appc and jspc Compilers

  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.

    You can edit Web Application deployment descriptors manually or using WebLogic Builder. For more information, see WebLogic Builder Online Help.

    For detailed information on the elements in the web.xml descriptor, see web.xml Deployment Descriptor Elements.

  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.

    You can edit Web Application deployment descriptors manually or using WebLogic Builder. For more information, see WebLogic Builder Online Help.

    For detailed information on the elements the weblogic.xml descriptor, see weblogic.xml Deployment Descriptor Elements.

  7. Package 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.)

    For detailed information about packaging Web Applications, see "WebLogic Server Application Packaging" in Developing WebLogic Server Applications.

  8. Auto-deploy the WAR file on WebLogic Server for testing purposes.

    For detailed information about auto-deploying components and applications, refer to "Tools for Deploying" in Deploying WebLogic Server Applications.

    While you are testing the Web application, you might need to edit the Web application deployment descriptors. You can do this manually or use WebLogic Builder. For more information, see WebLogic Builder Online Help.

  9. Deploy the WAR file on the WebLogic Server for production use or include it in an Enterprise ARchive (EAR) file to be deployed as part of an enterprise application.

    Refer to Deploying WebLogic Server Applications for detailed information about deploying components and 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 directory 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.

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

You 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 name of your Web Application.

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.

 


Web Application Developer Tools

BEA provides several tools 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 WebLogic Server.

WebLogic Builder is a graphical environment in which you edit an application's deployment descriptor XML files. You can view these XML files as you edit them graphically 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:

For more information on WebLogic Builder, see WebLogic Builder Online Help

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 "Tools for Deploying" in Deploying WebLogic Server Applications

BEA XML Editor

You can use the BEA XML Editor to create and edit XML files. You can also 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 Dev2Dev Online.

appc and jspc Compilers

This section discusses the appc and jspc compilers. The appc compiler allows compilation and validation of J2EE EAR files, EJB JAR files, and Web Application WAR files, whereas the jspc compiler only allows compilation of JSPs.

appc Compiler

The appc compiler compiles and generates J2EE EAR files, EJB JAR files, and Web Application WAR files for deployment. It also validates the descriptors for compliance with the current specifications at both the individual module level and the application level. The application level checks include checks between the application-level deployment descriptors and the individual modules as well as validation checks across the modules.

The appc compiler reports any warnings or errors encountered in the descriptors. Finally, the appc compiler compiles all of the relevant modules into an EAR file, which can be deployed to WebLogic Server.

appc Syntax

Use the following syntax to run appc:

prompt>java weblogic.appc [options] <ear, jar, or war file or directory>

appc Options

Option

Description

-print

Prints the standard usage message.

-version

Prints jspc version information.

-output <file>

Specifies an alternate output archive or directory. If not set, the output is placed in the source archive or directory.

-forceGeneration

Forces generation of EJB and JSP classes. Without this flag, the classes may not be regenerated (if determined to be unnecessary).

-lineNumbers

Adds JSP line numbers to generated class files to aid in debugging.

-basicClientJar

Does not include deployment descriptors in client JARs generated for EJBs.

-idl

Generates IDL (interface definition language) for EJB remote interfaces.

-idlOverwrite

Always overwrites existing IDL files.

-idlVerbose

Displays verbose information for IDL generation.

-idlNoValueTypes

Does not generate valuetypes and the methods and attributes that contain them.

-idlNoAbstractInterfaces

Does not generate abstract interfaces and methods and attributes that contain them.

-idlFactories

Generates factory methods for valuetypes.

-idlVisibroker

Generates IDL somewhat compatible with Visibroker 4.5 C++.

-idlOrbix

Generates IDL somewhat compatible with Orbix 2000 2.0 C++.

-idlDirectory <dir>

Specifies the directory where IDL files will be created (default : target directory or JAR)

-idlMethodSignatures <>

Specifies the method signatures used to trigger IDL code generation.

-iiop

Generates CORBA stubs for EJBs.

-iiopDirectory <dir>

Specifies the directory where IIOP stub files will be written (default : target directory or JAR)

-keepgenerated

Keeps the generated .java files.

-compiler <javac>

Selects the Java compiler to use.

-g

Compiles debugging information into a class file.

-O

Compiles with optimization on.

-nowarn

Compiles without warnings.

-verbose

Compiles with verbose output.

-deprecation

Warns about deprecated calls.

-normi

Passes flags through to Symantec's sj.

-J<option>

Passes flags through to Java runtime.

-classpath <path>

Selects the classpath to use during compilation.

-advanced

Prints advanced usage options.

The following are the available appc options:

appc Ant Task

You can use the following Ant task to invoke the appc compiler:

<taskdef name="appc" classname="weblogic.ant.taskdefs.j2ee.Appc"/>

jspc Compiler

The jspc compiler is a Java Servlet Page (JSP)-specific compiler. It offers more options for compiling JSPs than appc, and provides more control over how the JSPs are compiled.

jspc Options

Option

Description

-print

Prints the standard usage message.

-version

Prints jspc version information.

-webapp <dir>

Directory to be considered as the document root for resolving relative files.

-verboseJspc

Indicates whether jspc runs in verbose mode. The default is false.

-keepgenerated

Keeps the generated .java files.

-compiler <javac>

Indicates the Java compiler to use.

-compilerclass <null>

Loads the compiler as a class instead of an executable.

-classpath <path>

Classpath to use during compilation.

-d <dir>

Target (top-level) directory for compilation.

-advanced

Prints advanced usage options.

The following are the available jspc options:

jspc Syntax

Use the following syntax to run jspc:

prompt> java weblogic.jspc [options] <jsp files>...

jspc Usage Scenario

To compile all of the JSPs in a particular directory, use the following syntax:

java weblogic.jspc -webapp . -verboseJspc -d .\WEB-INF\classes

where:

To compile only a few select JSP files, use the following syntax:

java weblogic.jspc -webapp . -verboseJspc foo.jsp abc.jsp

 

Back to Top Previous Next