Friday, July 8, 2011

Web Applications Basics ( WAR files )

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:
  • At least 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 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. 

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.

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.
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.
The Web Application deployment descriptor that configures the Web Application.
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.
Contains server-side classes such as HTTP servlets and utility classes.
Contains JAR files used by the Web Application, including JSP tag libraries.

Creating Web Applications: Main Steps

Here are the main steps for creating a Web application:

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

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

Compile the servlets into class files.

Arrange the resources (servlets, JSPs, static files, and deployment descriptors) in the prescribed directory format. For more information on the Web application directory structure

Create the web.xml and weblogic.xml deployment descriptors.

The web.xml file defines each servlet and JSP page and enumerates enterprise beans referenced in the Web application. The weblogic.xml file adds additional deployment information for WebLogic Server.
Create the web.xml and weblogic.xml deployment descriptors manually or using WebLogic Builder.

Create a Web application staging directory and save the JSPs, HTML pages, and multimedia files referenced by the pages in the top level of the staging directory.Package the HTML pages, servlet class files, JSP files, web.xml file, and weblogic.xml file into a WAR file.

Store compiled servlet classes, taglibs, and, if desired, servlets compiled from JSP pages are stored under a WEB-INF directory in the staging directory. When the Web application components are all in place in the staging directory, you create the WAR file with the JAR command.

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

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.

URLs and Web Applications
You construct the URL that a client uses to access a Web Application using the following pattern:
is either a host name that is mapped to a virtual host or hostname:portNumber.
is the name of your Web Application.
is a servlet that is mapped to the servletPath.
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.

    No comments:

    Post a Comment