users@jersey.java.net

Re: [Jersey] Jersey servlet configuration issue

From: Craig McClanahan <Craig.McClanahan_at_Sun.COM>
Date: Tue, 03 Mar 2009 00:53:43 -0800

Dmitry Shaparev wrote:
> Hi,
>
>
> web.xml content looks as folows:
>
> <servlet>
>
> <servlet-name>JerseyServlet</servlet-name>
>
> <servlet-class>
>
> com.sun.jersey.spi.container.servlet.ServletContainer
>
> </servlet-class>
>
> <load-on-startup>1</load-on-startup>
>
> </servlet>
>
>
>
> <servlet-mapping>
>
> <servlet-name>JerseyServlet</servlet-name>
>
> <url-pattern>/*</url-pattern>
>
> </servlet-mapping>
>
>
>
> Jersey resource is not defined for HTTP request GET /readme.html, but
> readme.html is present in the context root of web application. Now
> Jersey states that readme.html is not found.
>
>
>
> Could Jersey servlet be configured (or it has an init parameter) to
> forward requests for resources that are not defined in Jersey to the
> underlying servlet container?
>
>
> Thanks.
The immediate cause of your problem is that the "/*" mapping intercepts
*all* requests to this webapp, which prevents the usual Tomcat handling
of static resources. One easy workaround is to map your Jersey requests
to some other pattern like "/api/*", but this is probably not the
desirable long term solution.

There is a very long, but quite interesting, thread on the Jersey Users
mailing list concerning this exact issue titled "Static references from
JSP" that started last September. The upshot is that, in the current
trunk code of Jersey (what will become version 1.0.3), you can install
Jersey as a servlet filter, rather than as a servlet, and bypass some of
the restrictions in the servlet mapping algorithm. An example of this
is one particular message from the thread[1], but it will make more
sense when you read the whole thing [2].

To try this out right now, you will need to use the latest and greatest
trunk code (version 1.0.3-SNAPSHOT).

Craig

[1] http://markmail.org/message/dvorvnxkvwph6jll
[2]
http://markmail.org/search/?q=static%20references%20from%20jsp#query:static%20references%20from%20jsp+page:1+mid:3udmgakd4umdds5y+state:results