To administer your WestHost account, please enter your
Domain Name or Server Manager Username.

Apache Tomcat 101

Apache Tomcat

To all Tomcat users out there, I’m sure many of you have had questions on how to get things up and running; questions like ‘Is Apache Tomcat the same thing as Tomcat?’, and ‘How do I get the :8080 to go away?’

What is Apache Tomcat?

Apache Tomcat and Tomcat are the same thing. Apache, in this case, is simply the parent project and does not refer to the Apache web server. Apache Tomcat acts as a servlet container that processes Java servlets/JSP pages. There are some specifications that can be made within the Apache web server to let Apache know whether or not to handle the request or pass it on to Tomcat for processing. These specifications are located in the mod_jk.conf (sometimes just jk.conf) file in the /etc/httpd/conf.d directory.

Great! So how do I get Apache Tomcat to find my JSP pages?

Dustin Olson

While a number of specifications can take place in the mod_jk.conf file, the most relevant is the JkMount directive. This is the option that tells Apache whether or not to pass the request on to Tomcat. If you create a new folder in the /var/tomcat5/webapps directory for your Java related content, which is where is should be, Apache will not know about it by default. If the folder is called ‘test’, for example, then you would be able to access the folder by going to http://yourdomain.com:8080/test/ but it would not work by going to just http://domain.com/test/ which is, of course, what most of you will want. To get this functionality, a JkMount directive would have to be used inside the jk.conf file. It would look as follows:

JkMount /test/* ajp13w

Once this change is made and Apache is restarted (notice, Tomcat does NOT need restarting in this case because it was an Apache directive in an Apache configuration file that was altered) then http://yourdomain.com/test/ will come up fine and will be handled by Tomcat, as desired. If you are familiar with SSH, you can use the ‘apachectl graceful’ command to restart Apache. Otherwise you can go in through your Site Manager under the Restart Account section and restart that way.

What if I want my Java web application to show up at http://yourdomain.com instead of http://yourdomain.com/folder/?

In this scenario, you will create a folder called ROOT (all upper case) inside the /var/tomcat5/webapps directory and put all of your java content in there. You will then setup the JkMount directive as follows and then restart Apache as mentioned above:

JkMount /* ajp13w

Now your Java web application is all up and running. That’s all it takes!

A few more tidbits for those who want to understand what all that means:

The ‘ajp13w’ entry above refers to a user specified in the /etc/httpd/conf/workers.properties file and stands for Apache JServ Protocol. To find out more on this protocol and its functions, see http://tomcat.apache.org/connectors-doc/ajp/ajpv13a.html. That should give you a good understanding of what role a Tomcat worker plays and how and why Tomcat processes are spawned and resources are used. A Tomcat worker is a Tomcat instance that is waiting to execute servlets or any other content on behalf of some web server. For example, we can have a web server such as Apache forwarding servlet requests to a Tomcat process (the worker) running behind it. In WestHost’s case, ajp13 and ajp12 are the only workers setup, ajp13 being the default worker, and the preferred worker due to it being configured to use sockets as it’s communication channel (see above link for further detail.) When the JkMount directive is used, it is assigned to the ajp13 worker as the entry specifies.

This entry was posted in Technical Support, Web site Development. Bookmark the permalink. Both comments and trackbacks are currently closed.

One Comment

  1. vps
    Posted June 6, 2009 at 8:55 am | Permalink

    That’s really so useful article. Thanks.

Copyright © 1998–2014, WestHost. All rights reserved.  |  WestHost / Believe in Better Hosting. Privacy Policy