The Web Archive (WAR) File

The portable distribution and deployment format for a web application defined by the servlet specification is the Web Archive (WAR). All Servlet 2.2–compliant servers provide tools for installing a WAR file and associating 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. The internal structure of the WAR file is defined by the servlet specification as:

/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
/WEB-INF/tlds/actions.tld

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. All these files can be accessed with a URI starting with the context path. For example, if the application was assigned the context path /sales, the URI /sales/products/list.jsp would be used to access the JSP page named list.jsp in the products directory.

The WEB-INF directory contains files and subdirectories for other types of resources. 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 ...

Get JavaServer Pages Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.