users@jersey.java.net

Re: [Jersey] Trailing slash on root resource

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 21 May 2009 09:34:24 +0200

On May 21, 2009, at 3:11 AM, Charles Brooking wrote:

> Hi all
>
> Is there a way to respond to the "root" address without a trailing
> slash?
>
> @Path("/")
> public class RootResource { ... }
>
> <servlet-mapping>
> <servlet-name>app</servlet-name>
> <url-pattern>/app/*</url-pattern>
> </servlet-mapping>
>
> I've found that the resource above only works with <http://localhost/app/
> >
> but that <http://localhost/app> gives a 404. Am I doing something
> wrong
> here?
>

No, it is one of those boundary cases with Servlet.

What servlet container are you using?

GF will redirect from http://localhost/app to http://localhost/app/

For example, with the bookstore sample:

# curl -v http://localhost:8080/bookstore
* About to connect() to localhost port 8080 (#0)
* Trying ::1... Connection refused
* Trying fe80::1... Connection refused
* Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /bookstore HTTP/1.1
> User-Agent: curl/7.16.3 (powerpc-apple-darwin9.0) libcurl/7.16.3
OpenSSL/0.9.7l zlib/1.2.3
> Host: localhost:8080
> Accept: */*
>
< HTTP/1.1 302 Moved Temporarily
< X-Powered-By: Servlet/2.5
< Location: http://localhost:8080/bookstore/
< Content-Type: text/html; charset=iso-8859-1
< Transfer-Encoding: chunked
< Date: Thu, 21 May 2009 07:33:44 GMT
<
* Connection #0 to host localhost left intact
* Closing connection #0

Paul.