bea.com | products | dev2dev | support | askBEA |
![]() |
![]() |
|
![]() |
e-docs > WebLogic Server > Developing Web Applications for WebLogic Server > Web Applications Basics |
Developing Web Applications for WebLogic Server
|
The following sections describe how to configure and deploy 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 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 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 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.
For detailed information about creating JSPs, see Programming WebLogic JSP
For detailed information about creating servlets, see Programming WebLogic HTTP Servlets and Programming WebLogic JSP
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
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.
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.
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.
Refer to Deploying WebLogic Server Applications for detailed information about deploying components and applications.
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.
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.
Web Application Developer Tools
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
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
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.
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.
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>
You can use the following Ant task to invoke the appc compiler:
<taskdef name="appc" classname="weblogic.ant.taskdefs.j2ee.Appc"/>
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.
Directory to be considered as the document root for resolving relative files. |
|
Indicates whether jspc runs in verbose mode. The default is false. |
|
Use the following syntax to run jspc:
prompt> java weblogic.jspc [options] <jsp files>...
To compile all of the JSPs in a particular directory, use the following syntax:
java weblogic.jspc -webapp . -verboseJspc -d .\WEB-INF\classes
To compile only a few select JSP files, use the following syntax:
java weblogic.jspc -webapp . -verboseJspc foo.jsp abc.jsp
![]() |
![]() |
![]() |
![]() |
||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |