Home
Web applications
A Web application server publishes the contents of a WAR file under a defined URL root (called a context root) and then directs Web requests to the right resources and returns the appropriate Web response to the requestor. Some requests can be simply mapped to a simple static resource (such as HTML files and images) while others are mapped to a specific JSP or servlet class, which are referred to as dynamic resources. It is through these requests that the Java logic for a Web application is initiated and calls to the main business logic are processed.
When a Web request is received, the application server looks at the context root of the URL to identify which WAR the request is intended for, then the server looks at the contents after the root to identify which resource to send the request to. This might be a static resource (html file), the contents of which are simply returned, or a dynamic resource (servlet or JSP), where the processing of the request is handed over to JSP or servlet code.
In every WAR file there is descriptive meta information that describes this information and guides the application server in its deployment and execution of the servlets and JSPs within the Web application.
The structure of these elements within the WAR file is standardized and compatible between different Web application servers. The Java EE specification defines the hierarchical structure for the contents of a Web application that can be used for deployment and packaging purposes. All Java EE compliant servlet containers, including the test Web environment provided by Rational Application Developer, support this structure.
The structure of a WAR file (and an EAR file) is shown in Figure | -2.
Figure 13-2 Structure of EAR and WAR files
The web.xml file (also referred to as the deployment descriptor) is read on deployment by the Web application server and guides the setting up and running of the application. In particular, it has configuration information for starting up the servlets and then ensuring that Web requests are mapped to the right servlet or JSP. It also contains information about security (which user groups can access a particular set of URLs), filters (a mechanism to call some Java code before a request is processed), listeners (a mechanism to call some Java code on certain events), and configuration parameters to be passed to servlets or the application as a whole.
There are no requirements for the directory structure of a Web application outside of the WEB-INF directory. All these resources are accessible to clients (general Web browsers) directly from a URL given the context root. Naturally, we recommend that you structure the Web resources in a logical way for easy management (for example, an images folder to store graphics).
ibm.com/redbooks