tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joe Emenaker" <>
Subject Re: URL to servlet mapping with mod_jk
Date Fri, 01 Feb 2002 00:41:04 GMT

> quick question:
> how do I map a servlet to a URL using mod_jk
> eg I have /MyApp/WEB-INF/classes/dir1/dir2dir3/MyServlet.class
> and I want that to http://host/MyApp/MyServlet

It can get really confusing to get all of this mess straight....

You need to do three things:
 1 - Let Tomcat know about webapp
 2 - Let Tomcat know about that particular servlet within the webapp.
 3 - Let Apache know about the webapp

Probably the easiest way would be to use
   <AutoWebApp dir="/" host="" />

This should generate most of the JkMount commands and stuff in
mod_jk.conf... which you should be including in your Apache config from

There are a couple of problems with this method, though. First, directories
for AutoWebApp are supposed to be relative to Tomcat's home dir. So, I doubt
that you can really specify a directory in the root of your filesystem like
you have there. You may have to move your "MyApp" directory to something
below Tomcat's home.... usually $TOMCAT_HOME/webapps is where you'd put it.
In fact, your stock Tomcat server.xml probably already has an AutoWebApp for
that directory... in which case it should just automatically find and
include your webapp the next time you restart Tomcat.

The second problem is that, with AutoWebApp, Tomcat will try to create a
webapp for every directory there that it finds. If you have "MyApp" in your
root of your filesystem, I think Tomcat will try to make a webapp for /etc,
/usr, /home, /var.... it would probably get a little ugly.

Now, recall that you've got:

that you want mapped to:

This is configured in your /MyApp/WEB-INF/web.xml file. You need to add two
things. First, you need to give an internal name to a class file that will
behave as a servlet:


Then, you tell Tomcat that you want a certain URL pattern to invoke that
servlet that you just gave a name to.


STEP 3 - Making Apache pass the appropriate stuff to Tomcat....
You do this with "JkMount" in your Apache config files.

Look in the mod_jk.conf that Tomcat should have generated. (If it didn't
geenerate it, then read about the "ApacheConfig" directive for server.xml.).
You should see something along the lines of:

    JkMount   /MyApp     ajp13
    JkMount   /MyApp/*  ajp13

If you don't see these in any files that Apache is looking in, then I think
you'll need to add them. They tell Apache which URL patterns to forward to
Tomcat. Note, you probably also want a server-wide JkMount for "*.jsp" so
that all JSP pages get processed by Tomcat.

Hope this helps...

- Joe

To unsubscribe:   <>
For additional commands: <>
Troubles with the list: <>

View raw message