In the previous many chapters, we learnt in depth about JSPs and Servlets. The next step is to learn how to deploy the various components of your web application. This is exactly what you are going to learn in this and the next few chapters.
So, lets get started!!!
Web Application and Web Archive Structure
Any Web Application has a hierarchical structure (of folders) that is used for packaging the web applications.
The application needs a reference point within the hierarchical structure. Here, let's call it TOMCAT_HOME. This represents the root of your server (Tomcat) installation, not your Web application root. Remember that we have been using Tomcat as the server of our choice as part of this SCWCD certification series.
When we talk of a Web application's context, we are referring to that Web application's root directory or path within a particular server. A special directory exists within the application hierarchy named WEB-INF. This directory contains all things related to the application that aren't in the document root of the application. It is this WEB-INF directory that is the Web application's root directory, also referred to as the context. The most important file here is web.xml, the name of the WebApp deployment descriptor.
Let us take a look at the various contents (files & folders) that will be present inside this WEB-INF directory:
1. /WEB-INF/web.xml – This is the Deployment Descriptor file
2. /WEB-INF/classes/ - This is the directory where all your java class files will be placed
3. /WEB-INF/lib/ - This is the folder where all your JAR files go.
The following is the Web application structure for a small sample Web application:
Although the actual paths are not on the exam, seeing where the files actually go illustrates what is going on.
For ex: my tomcat is installed in c:\dev\java\jakarta-tomcat-4.0.1. This is my TOMCAT_HOME. Remember that, this path that is referred by TOMCAT_HOME might vary from Pc to Pc depending on the installation preferences of the user.
The good thing is, Tomcat knows to look in c:\dev\java\jakarta-tomcat-4.0.1\webapps director for web applications.
From here you will configure Tomcat, or another container, with XML files. For example, Tomcat installs with an example application. In the C:\dev\java\jakarta-tomcat-4.0.1\conf or just TOMCAT_HOME\conf directory there is a server.xml file. Tomcat uses this to configure itself upon starting. There is a context element that you use to map your application's URL to the actual directory path.
The following is how you get an examples application:
< ! - - Tomcat Examples Context - - >
< Context path="/examples" docBase="examples" debug="0" reloadable="true" >
So, now that you have an examples Web application, the actual root directory is this: TOMCAT_HOME\webapps\examples. If you had the file TOMCAT_HOME\webapps\examples\hello.jsp you would call this file with http://localhost:8080/examples/hello.jsp.
Whenever you type a URL in your browsers address bar, Tomcat converts the URLs into corresponding Paths that it can understand and process. They are:
|installation root||-||C:\dev\java\jakarta-tomcat-4.0.1 This is TOMCAT_HOME.|
There is a lot more to learn about deployment and packaging, which we will be looking in depth in the subsequent chapters. For now, this chapter is over.
Previous Chapter: Chapter 46 - JSP API
Next Chapter: Chapter 48 - Elements of the Deployment Descriptor