ContentsPreviousNextTomcat-Book Project

Well, now that you have a rough outline of Tomcat, you may want to customize it to do exactly what you want. Lets have a quick look at the server.xml in the conf directory. Please note that this is not intended to be an advanced, or even medium level configuration discussion. Rather it is aimed at the newbie wanting to learn the configuration basics.

Open up the server.xml file in your favourite editor. You will find that it is very well commented. Take the time to read the comments and you will probably find that most of what you read here becomes obvious.

The first section of configuration is logging. Read the comments.

Good, you've read them haven't you? No? Go back and read them. Ok, now, you'll see that the default install has three different logs set up. The first, tc_log, is where Tomcat will log its output. You probably want to change this setting so that its output goes into a file - logs/tomcat.log. The second log is the servlet_log. This is where Servlet.log() calls will go. The final log is JASPER_LOG. This is used for Jasper, which is what Tomcat uses for compiling JSPs.

The next item is the ContextManager. You'll notice it has a parameter workDir="work". This relates to compiling JSPs as mentioned above. Inside the ContextManager are a number of ContextInterceptors. This should give you a bit of a hint about the way Tomcat operates. I wont go through each one, but its worth looking at their configuration and thinking about what must be going on behind the scenes.

After the ContextInterceptors are a series of RequestInterceptors. Again, these have useful comments. The first might be particularly useful. The SessionInterceptor works in two modes - with and without cookies. You may need to turn cookies off because of some of your clients - this is where you do it. You should also look at the remaining RequestInterceptors, particularly the realm interceptors - these will be covered in Chapter XXX.

After the RequestInterceptors come the Connectors. We are now into the guts of the configuration. The first connector is for HTTP. You may have wondered before why we requested http://localhost:8080. Well, this is it. To turn off HTTP access (which you may want to do if you've integrated with Apache) remove (or comment out) this connector. You can change the port on which Tomcat listens by changing the port parameter.

You'll notice the next connector is commented out. It is the SSL connector, and requires SSL support to be compiled in.

The next connector is the Ajp12ConnectionHandler. This is used for communication between Apache and Tomcat. This version is becoming deprecated, and after getting comfortable with Tomcat you would be well advised to use the Ajp13ConnectionHandler for connections between Apache and Tomcat. Note the comment that it is also used to shutting down Tomcat, and hence you will not be able to remove it from the Tomcat altogether even after using the newer version.

The final part of the configuration file is the Contexts. Note that if you simply place all your .war files in the webapps directory you do not need to explicitly define any Contexts. However, to change the path of the web application and set up virtual hosts you will need to explicitly define your Contexts in the server.xml file. These topics are covered in Chapter XXX.

ContentsPreviousNext