Jersey JAX-RS:以斜杠(/)结尾的路径会导致404错误

Jersey JAX-RS:以斜杠(/)结尾的路径会导致404错误,jersey,jax-rs,Jersey,Jax Rs,尝试在处访问资源会导致HTTP 404(未找到)错误。尝试达到预期的工作中的同一资源 会话资源: @GET @Path("/new") @Produces(MediaType.TEXT_HTML) public Viewable newSession() { Map<String, Object> map = new HashMap<String, Object>(); map.put("method","secEnterprise"); //

尝试在处访问资源会导致HTTP 404(未找到)错误。尝试达到预期的工作中的同一资源

会话资源:

@GET
@Path("/new")
@Produces(MediaType.TEXT_HTML)
public Viewable newSession() {

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("method","secEnterprise");

    // create authentication form
    return new Viewable("/session/new", map);

}

请求被自动路由到,因此自动重定向的某些方面工作正常。

不确定您正在使用哪个实现,但引用了Jersey文档:


@Path值可能以“/”开头,也可能不以“/”开头,这没有什么区别。同样,默认情况下,@Path值可能以“/”结尾,也可能不以“/”结尾,这没有什么区别,因此,以“/”结尾或不以“/”结尾的请求URL都将匹配。但是,Jersey有一个重定向机制,如果启用该机制,则会在请求URL不以“/”结尾且匹配的@Path以“/”结尾时自动重定向到以“/”结尾的请求URL。

Jersey 1.8。我在文档中也看到了这一点。我想我已经启用了重定向:com.sun.jersey.config.feature.Redirect=true(参见web.xml)。
<filter>
    <filter-name>jersey</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>com.businessobjects.resources</param-value>
    </init-param>        
    <init-param>
        <param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name>
        <!-- is this capturing the '/' and redirecting it to a non-existent view (.JSP)? -->
        <param-value>/((WEB-INF/views))/.*</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.config.property.JSPTemplatesBasePath</param-name>
        <param-value>/WEB-INF/views/</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.config.feature.Redirect</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.config.feature.FilterForwardOn404</param-name>
        <param-value>true</param-value>
    </init-param>        
</filter>

<filter-mapping>
    <filter-name>jersey</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<!-- new.jsp -->
...
<form method="post" action="session">
...
<form method="post" action="/enterprise/session">
<form method="post" action="/enterprise/session/">
@Path("/")
public class HomeResource {

    @GET
    public Response index() {
        return Response.ok(new Viewable("/home/index")).build();
    }
}