[ Team LiB ] Previous Section Next Section

Tomcat Configuration

Tomcat provides a great deal of flexibility in configuration. However, for the most part, Tomcat configuration is very straightforward.

What We'll Cover


In this section, we'll cover some of the most common configuration tasks. There are many configurations that are not covered here. For a current view of the options, refer to the current documentation for Tomcat.

In the conf directory is a file called server.xml. Most of the directives in server.xml deal with logging and various worker classes within the Tomcat server. The part of the file you might want to edit is the section that defines contexts.

Contexts represent Web applications. In essence, they're like virtual directories where application resources reside. You may recall that when you add a WAR file to the webapps directory and restart Tomcat, the application appears in a context that is the same as the name of the WAR file. For example, if you copied jspbook.war (which had a JSP called myApp.jsp) to the webapps directory and restarted Tomcat, you would access the application this way:


You can see that the context appears as though it were a path in the URL used to access myApp.jsp.

If you want to manually add a context that represents resources contained in h:\jspbook and you want to access it from Tomcat via the URL http://localhost/jspbook, you would add a context mapping to the server.xml file like this:

<Context path="/jspbook" docBase="h:/jspbook" debug="0" reloadable="true" >

You must restart Tomcat to pick up any additional contexts. If you are using the Apache Tomcat integration, Tomcat automatically adds any new contexts to its tomcat-apache.conf file, so when you restart Apache it will also know about the new directory.

The web.xml file contains the configuration for the default Web application. The file's format is identical to the format used for Web Archive (WAR) files. You can find more information on the format of WAR files in Appendix B, "Packaging a Web Application."

    [ Team LiB ] Previous Section Next Section