|< Day Day Up >|
F.1 Web Application File Structure
The portable distribution and deployment format for a web application defined by the servlet specification is the Web Application Archive (WAR). All Servlet 2.2-compliant servers (or later) provide tools for installing a WAR file and associate the application with a servlet context.
A WAR file has a .war file extension and can be created with the Java jar command or a ZIP utility program, such as WinZip, as described at the end of this appendix. The internal structure of the WAR file is defined by the servlet specification:
/index.html /company/index.html /company/contact.html /company/phonelist.jsp /products/searchform.html /products/list.jsp /images/banner.gif /WEB-INF/web.xml /WEB-INF/lib/bean.jar /WEB-INF/lib/actions.jar /WEB-INF/classes/com/mycorp/servlets/PurchaseServlet.class /WEB-INF/classes/com/mycorp/util/MyUtils.class ...
The top level in this structure is the document root for all application web page files. This is where you place all your HTML pages, JSP pages, and image files. A browser can access all these files, using a URI starting with the context path. For instance, if the application has been assigned the context path /sales, the URI /sales/products/list.jsp is used to access the JSP page named list.jsp in the products directory in this example.
F.1.1 Placing Java Class Files in the Right Directory
The WEB-INF directory contains files and subdirectories for other types of resources used by the application. Files under this directory aren't directly accessible to a browser. Two WEB-INF subdirectories have special meaning: lib and classes. The lib directory contains JAR files with Java class files, for instance JavaBeans classes, custom action handler classes, and utility classes. The classes directory contains class files that are not packaged in JAR files. The web application automatically has access to all class files in the lib and classes directories (in other words, you do not have to add them to the CLASSPATH environment variable).
If you store class files in the classes directory, they must be stored in subdirectories mirroring the package structure. For instance, if you have a class named com.mycorp.util.MyUtils, you must store the class file in WEB-INF/classes/com/mycorp/util/MyUtils.class. Another type of file that can be stored in the classes directory is the type of a resource properties file containing localized text, as described in Chapter 11.
The WEB-INF directory can also contain other directories. For instance, a directory named tlds is by convention used for tag library Tag Library Descriptor (TLD) files when they are not packaged in JAR files.
During development it's more convenient to work with the web application files in a regular filesystem structure instead creating a new WAR file every time something changes. Most containers therefore support the WAR structure in an open filesystem as well. The book example application is distributed as an open filesystem structure to make it easier for you to see all the files.
|< Day Day Up >|