How do I make servlet aliasing work with Apache+Tomcat?

Ken Kress

[See How do I use servlet aliasing? for background.]

Chapter 13 of the Java Servlet Specification v2.2, gives an example of using a "deployment descriptor" to add a new path to a servlet. The problem is the technique shown fails when you integrate Tomcat with Apache.

When you use Tomcat standalone as your web server, you can modify the web.xml in $TOMCAT_HOME/webapps/myApp/WEB-INF to add a url-pattern:

This will let you use: http://webserver:8080/myApp/jsp-bin/stuff.html instead of: http://webserver:8080/myApp/servlet/myServlet/stuff.html But it won't work on port 80 if you've integrated Tomcat with Apache. Graeme Wallace provided this trick to remedy the situation. Add the following to your tomcat-apache.conf (or to a static version of it, since tomcat re-generates the conf file every time it starts):
<LocationMatch /myApp/jsp-bin/* >
    SetHandler jserv-servlet

This lets Apache turn over handling of the url pattern to your servlet.
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact