JSP on Windows: Apache 2, Tomcat 4.1, JK 2

Introduction

This document describes how to set up a working JSP system that connects to Apache on Windows (I'm working on 2K). This system lets you process JSP files that are in the ordinary Web server folders as well as use specific Web applications.

The system created is a simple one that handles only a single host, not virtual hosts (although if you know about virtual hosts maybe you can extend it). We are using Apache 2.0.48, JK 2.0.43, and Tomcat 4.1.29 (the current versions at time of first writing).

Important: all other documents describing this process are wrong. They miss out vital configuration steps. You're going to spend all day tearing your hair out if you believe them, so don't do that, that's what I just did. Also, don't bother looking at Apache's docs on this subject - unless they rewrote them since, they're utterly worthless.

Also important: I make no guarantees about security implications (or whether this actually works for that matter; hey, most likely this document is wrong too). And this document doesn't cover other versions of the software, like Apache 1 for example.

Really really important: Under no circumstances contact me asking for help configuring your software. Don't email me about that. I don't know shit about server configuration. If it doesn't work, ask somebody who does, not me. (On the other hand, if you are somebody who knows about server configuration and you notice anything hideously wrong in here, let me know, maybe I'll fix it, thanks.)

Thanks to Eric Barr for pointing out an omission in the previous version of this text.

Basic installation

Remember the directories you used to install Apache and Tomcat in. I'm going to call those <APACHE> and <TOMCAT>.

Set up Tomcat

Edit server.xml

Begin by editing the file <TOMCAT>/conf/server.xml. You might want to make a backup first.

Required task

First thing is to make sure Tomcat is looking in the same place as Apache for your JSP files. Otherwise it ain't gonna find them, even if Apache does pass on the request. (If you only want to use Tomcat web applications and don't need JSP files processed inside your Apache folders, then you can skip this step.)

(Obviously, if you changed your Apache document root from the default, use that instead.)

Optional tasks

Set up Apache

Edit workers2.properties

You're probably thinking, huh? my Apache doesn't have one of those files. Well, it doesn't yet, but you're going to make one.

Edit httpd.conf

Finally, a file you've actually heard of! Add this to httpd.conf (e.g. at the end):

LoadModule jk2_module modules/mod_jk2-2.0.43.dll

<Location "/*.jsp">
  JkUriSet worker ajp13:localhost:8009
</Location>

<Location "/tomcat-docs">
  JkUriSet worker ajp13:localhost:8009
</Location>

You can probably see that this causes all files ending .jsp, and anything beginning with /tomcat-docs (you can get rid of that one if you like, it's just an example), to be processed by Tomcat instead of Apache.

Any webapps (like tomcat-docs) will come from within the Tomcat webapps folder, but all your JSP files can be placed inside the normal Apache root.

If you want to make other URIs be processed by Tomcat, you can just add them in the same way. Hopefully it's obvious how - and because this goes in httpd.conf you don't have to remember some other bizarre configuration file when you're making changes.

Restart services

You'll need to use the Services control panel.

Rumours suggest you should wait a few seconds between these, but I don't think it matters any more (maybe it once did).

Test!

Webapp test

Make sure Tomcat webapps still work by accessing http://localhost/tomcat-docs/ - you should find that this works, even though you accessed it via Apache (port 80) and the files are within Tomcat's webapps folder. That's because it's configured to pass on the request in httpd.conf.

JSP file test

Within your Apache documents tree, create a file test.jsp:

<%= new java.util.Date() %>

Request http://localhost/test.jsp and you should see (after a pause, first time round) the current date. Woo! Again, that's because *.jsp is configured to pass on the request, in httpd.conf.

End

That's all for now folks!