2012-02-14 129 views
2

嘗試訪問資源http://localhost:8080/enterprise/session/new/會導致HTTP 404(未找到)錯誤。嘗試按預期方式在http://localhost:8080/enterprise/session/new上訪問相同的資源。JAX-RS:以斜槓結尾的路徑(/)導致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); 

} 

查看位於WEB-INF \意見\會議\ new.jsp

我懷疑是問題的一部分,關係到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> 

我不知道這是否是相關的,但視圖的形式POST到/會話/會話,而不是僅僅/會話:

<!-- new.jsp --> 
... 
<form method="post" action="session"> 
... 

我錯過了什麼?如預期

**編輯** 0

更改表單元素的action屬性來

<form method="post" action="/enterprise/session"> 

作品。然而,結尾斜槓:

<form method="post" action="/enterprise/session/"> 

導致與前面提到的相同的錯誤。

似乎正則表達式/((WEB-INF/views))/.*需要更改爲忽略結束斜線('/')。

**編輯** 1

我有一個根資源:

@Path("/") 
public class HomeResource { 

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

請求http://localhost:8080/enterprise被自動路由到http://localhost:8080/enterprise/,所以自動重定向的某些方面工作正常。

回答

1

不知道你正在使用,但來自新澤西州的文檔引用其實現:

一個@Path值可能會或可能不會與一個「/」,這都沒有區別開始。同樣,默認情況下,@Path值可能會或可能不會以'/'結尾,它沒有區別,因此請求以'/'結尾或不以'/'結尾的URL都將被匹配。但是,Jersey具有重定向機制,如果啓用,如果請求URL不以'/'結尾且匹配的@Path以'/'結尾,則自動執行重定向到以'/'結尾的請求URL。

+0

澤西島1.8。我在文檔中也看到了這一點。我想我已啓用重定向:com.sun.jersey.config.feature.Redirect = true(請參閱web.xml)。 – craig 2012-02-14 18:45:15

相關問題