Developing Web Applications for WebLogic Server
The following sections provide an overview of WebLogic Server Web applications:
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.
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 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 (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 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. See Creating WebLogic Server Applications in Developing WebLogic Server Applications.
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 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 (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 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 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. See Creating WebLogic Server Applications in Developing WebLogic Server Applications.
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.
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, you must set context-root to "/" in the weblogic.xml deployment descriptor file.)
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 (JDBC), JavaMessaging Service (JMS), XML, and more.
The following is an example of a Web application directory structure, in which myWebApp/ is the staging directory:
Listing 1-1 Web Application Directory Structure
myWebApp/
WEB-INF/
web.xml
weblogic.xml
lib/
MyLib.jar
classes/
MyPackage/
MyServlet.class
index.html
index.jsp
The following steps summarize the procedure for creating a Web application as part of an Enterprise application using the split development directory structure. SeeCreating WebLogic Server Applications in Developing WebLogic Server Applications.
You may want to use developer tools included with WebLogic Server for creating and configuring Web applications. See Web Application Developer Tools.
application.xml
and weblogic-application.xml
) in the META-INF\ directory. See Enterprise Application Deployment Descriptors in Developing WebLogic Server Applications. You can automatically generate the Enterprise application descriptors using the DDInit Java utility by executing the following command:
java weblogic.marathon.ddinit.EarInit \myEAR
For more information on DDInit, see Using the WebLogic Server Java Utilities.
You can automatically generate the Web application descriptors using the DDInit utility by executing the following command:
java weblogic.marathon.ddinit.WebInit \myEAR\myWebApp
For more information on DDInit, see Using the WebLogic Server Java Utilities.
Once you have set up your directory structure, you create the build.xml file using the weblogic.BuildXMLGen utility. See Creating WebLogic Server Applications in Developing WebLogic Server Applications.
Note: The wlpackage Ant task places compiled versions of your Java source files in the build directory. For example: /build/myEAR/myWebApp/classes.
You construct the URL that a client uses to access a Web application using the following pattern:
http://hoststring
/ContextPath
/servletPath
/pathInfo
If you are using virtual hosting, you can substitute the virtual host name for the hoststring
portion of the URL.
BEA provides several tools to help you create and configure Web applications.
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
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
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.) See BEA dev2dev Onlinehttp://dev2dev.bea.com/index.jsp.
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.
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
For a complete list of appc options, see Compiling Java Code in Developing WebLogic Server Applications
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
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. For information on creating policies using the Administration Console, see the Online Help.
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.
For detailed instructions and an example on configuring security in Web applications, see Securing WebLogic Resources. For more information on WebLogic security, refer to Programming WebLogic Security.