users@jersey.java.net

Re: [Jersey] Tomcat, trailing slashes and welcome files

From: Trolly Rogers <trolly.s.rogers_at_gmail.com>
Date: Sat, 6 Mar 2010 09:41:28 -0500

Howdy Gregg - What I do is define my Jersey ServletContainer as a filter
instead of a servlet and then define the WebPageContentRegex init param
which tells jersey the things that shouldn't serve (like jsp files). The
regexp param-value below probably isn't the best example of what to use, but
you get the point.

FYI... I'm using tomcat 6 with Jersey 1.1.5 with.

<filter>
    <filter-name>Jersey Filter</filter-name>

<filter-class>com.sun.jersey.spi.container.servlet.ServletContainer</filter-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>your package name(s)</param-value>
        </init-param>
    <init-param>

<param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name>

<param-value>.*\.jsp|.*\.css|.*\.png|.*\.js|.*\.gif|.*\.jpg</param-value>
        </init-param>
</filter>

<filter-mapping>
    <filter-name>Jersey Filter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
</filter-mapping>

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

On Fri, Mar 5, 2010 at 8:03 PM, Gregg Carrier <greggcarrier_at_gmail.com>wrote:

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