top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

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

+3 votes
548 views
How do I make servlet aliasing work with Apache+Tomcat?
posted Dec 14, 2015 by Dominic

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

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:

             <web-app>
              <servlet>
                <servlet-name>
                          myServlet
                </servlet-name>
                <servlet-class>
                          myServlet
                </servlet-class>
              </servlet>
              <servlet-mapping>
                <servlet-name>
                          myServlet
                </servlet-name>
                <url-pattern>
                          /jsp-bin/*
                </url-pattern>
             </servlet-mapping>
           </web-app>

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
          </LocationMatch>

This lets Apache turn over handling of the url pattern to your servlet

answer Dec 15, 2015 by Karthick.c
...