Web Applications Basics

 


Contents

  1. Overview
  2. Main Steps to Create a Web Application
  3. URLs and Web Applications
  4. Web Application Developer Tools
  5. Web Application Security

See Also

  1. Developing WebLogic Server Applications
  2. Deploying WebLogic Server Applications

 


Overview

A Web application contains an application's resources, such as servlets, JavaServer Pages, 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. 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 attributes.

JSPs and HTTP servlets can access all services and APIs available in WebLogic Server. These services include EJBs, database connections via Java Database Connectivity, JavaMessaging Service, 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:

  • One servlet or Java Server Page (JSP), along with any helper classes.

  • A web.xml deployment descriptor, which is a J2EE standard XML document that describes the contents of a WAR file.

  • A weblogic.xml deployment descriptor, which is an XML document containing WebLogic Server-specific elements for Web applications.

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

BEA recommends that you package and deploy your stand-alone Web applications as part of an Enterprise application. This is a BEA best practice, which allows for easier application migration, additions, and changes. Also, packaging your applications as part of an Enterprise application allows you to take advantage of the split development directory structure, which provides a number of benefits over the traditional single directory structure.

If you are deploying a directory in exploded format (not archived), do not name the directory .ear, .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.

 

Java Server Pages

Java Server Pages 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 appc compiler weblogic.appc generates JSPs and validates descriptors.

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. BEA recommends that you package and deploy your WAR file as part of an Enterprise application. This is a BEA best practice, which allows for easier application migration, additions, and changes. Also, packaging your Web application as part of an Enterprise application allows you to take advantage of the split development directory structure, which provides a number of benefits over the traditional single directory structure.

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 WEB-INF directory contains the deployment descriptors for the Web application (web.xml and 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.

All servlets, classes, static files, and other resources belonging to a Web application are organized under a directory hierarchy.

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

    (To make your Web application the default Web application, set context-root to "/" in the weblogic.xml deployment descriptor file.)

  2. DefaultWebApp/WEB-INF/web.xml

    The Web application deployment descriptor that configures the Web application.

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

  4. DefaultWebApp/WEB-INF/classes

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

  5. DefaultWebApp/WEB-INF/lib

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

The entire directory, once staged, is bundled into a WAR file using the jar command. The WAR file can be deployed alone or as part of an Enterprise application (recommended) 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, JavaMessaging Service, XML, and more.

The following is an example of a Web application directory structure, in which myWebApp/ is the staging directory:

myWebApp/
 WEB-INF/
  web.xml
  weblogic.xml
  lib/
   MyLib.jar
  classes/
   MyPackage/
    MyServlet.class
 index.html
 index.jsp

 


Main Steps to Create a Web Application

The following steps summarize the procedure for creating a Web application as part of an Enterprise application using the split development directory structure.

You may want to use developer tools included with WebLogic Server for creating and configuring Web applications.

 

Step One: Create the Enterprise Application Wrapper

  1. Create a directory for your root EAR file:

    \src\myEAR\

  2. Set your environment as follows:

    • On Windows NT, execute the setWLSEnv.cmd command, located in the directory server\bin\, where server is the top-level directory in which WebLogic Server is installed.

    • On UNIX, execute the setWLSEnv.sh command, located in the directory server/bin/, where server is the top-level directory in which WebLogic Server is installed and domain refers to the name of your domain.

  3. Package your Enterprise application in the \src\myEAR\ directory as follows:

    1. Place the Enterprise applications descriptors (application.xml and weblogic-application.xml) in the META-INF/ directory.

      You can automatically generate the Enterprise application descriptors using the DDInit Java utility by executing the following command:

      java weblogic.marathon.ddinit.EarInit \myEAR

    2. Edit the deployment descriptors as needed to fine-tune the behavior of your Enterprise application.

    3. Place the Enterprise application .jar files in:

      \src\myEAR\APP-INF\lib\

 

Step Two: Create the Web Application

  1. Create a directory for your Web application in the the root of your EAR file:

    \src\myEAR\myWebApp

  2. Package your Web application in the \src\myEAR\myWebApp\ directory as follows:

    1. Place the Web application descriptors (web.xml and weblogic.xml) in the /src/myEAR/myWebApp/WEB-INF/ directory.

      You can automatically generate the Web application descriptors using the DDInit utility by executing the following command:

      java weblogic.marathon.ddinit.WebInit \myEAR\myWebApp

    2. Edit the deployment descriptors as needed to fine-tune the behavior of your Enterprise application.

    3. Place all HTML files, JSPs, images and any other files referenced by the Web application pages in the root of the Web application:

      \src\myEAR\myWebApp\images\myimage.jpg
      \src\myEAR\myWebApp\login.jsp
      \src\myEAR\myWebApp\index.html

    4. Place your Web application Java source files (servlets, tag libs, other classes referenced by servlets or tag libs) in:

      \src\myEAR\myWebApp\WEB-INF\src\

 

Step Three: Creating the build.xml File

Once you have set up your directory structure, you create the build.xml file using the weblogic.BuildXMLGen utility.

 

Step Four: Execute the Split Development Directory Structure Ant Tasks

  1. Execute the wlcompile Ant task to invoke the javac compiler. This compiles your Web application Java components into an output directory:

    /build/myEAR/WEB-INF/classes.

  2. Execute wlappc Ant task to invoke the appc compiler. This compiles any JSPs and container-specific EJB classes for deployment.

  3. Execute the wldeploy Ant task to deploy your Web application as part of an archived or exploded EAR to WebLogic Server.

  4. If this is a production environment (rather than development), execute the wlpackage Ant task to package your Web application as part of an archived or exploded EAR.

    The wlpackage Ant task places compiled versions of your Java source files in the build directory. For example:

    /build/myEAR/myWebApp/classes

 


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:

  • Generate deployment descriptor files for a J2EE module

  • Edit a module's deployment descriptor files

  • Compile and validate deployment descriptor files

  • Deploy a J2EE application to a server

 

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.

 

XML Editors

To create and edit XML files, you can use an XML Editor with DTD validation, such as BEA XML Editor on dev2dev or XMLSpy. An evaluation copy of XMLSpy is bundled with this version of WebLogic Server.

 

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>

For example, to validate the descriptors in myWebApp.war, as well as compile the jsp files and update the WAR file with the resulting class files, you would execute the following command:

java weblogic.appc -keepgenerated myWebApp.war

 

appc Options

For a complete list of appc options, see Compiling Java Code" in Developing WebLogic Server Applications

 

wlappc Ant Task

Use the wlappc Ant task to invoke the appc compiler:

<wlappc source="${dest.dir}" /> 

For a complete list of wlappc options, see Compiling Java Code" in Developing WebLogic Server Applications

 


Web Application Security

You can secure a Web application by restricting access to certain URL patterns in the Web application or programmatically using security calls in your servlet code.

At runtime, your username and password are authenticated using the applicable
security realm for the Web application. Authorization is verified according to the security constraints configured in web.xml or the external policies that might have been created using Administration Console for the Web application.

At runtime, the WebLogic Server active security realm applies the Web application security constraints to the specified Web application resources. Note that a security realm is shared across multiple virtual hosts.

Skip navigation bar  Back to Top Previous Next