users@jersey.java.net

Tomcat, trailing slashes and welcome files

From: Gregg Carrier <greggcarrier_at_gmail.com>
Date: Fri, 5 Mar 2010 17:03:52 -0800

I know this is probably a Tomcat problem, but I'm hoping someone may have
run into this issue and can offer some advice.

Desired behavior: I want all requests to my webapp to be handled by Jersey
except requests for index.jsp or the root of the webapp. I do not want
trailing slashes to be required in order to load URLs.

The setups I have tried and the results:

1 - <servlet-mapping>
        <servlet-name>Jersey Spring Web Application</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

In this case, the index.jsp loads fine at /mywebapp/. The servlet handles
all other requests appropriately EXCEPT it requires a trailing slash at the
end of all URLs. Eg, /mywebapp/foo/ loads but /mywebapp/foo does not. This
setup would be perfect except for the trailing slash requirement. I want it
to load with or without the trailing slash.

2 - <servlet-mapping>
        <servlet-name>Jersey Spring Web Application</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

With this setup the servlet handles requests with and without the trailing
slash (correctly). The index.jsp will not load at /mywebapp/ or
/mywebapp/index.jsp.

Any ideas? Thanks very much!

Gregg