2014-02-21 98 views
1

有人可以用簡單的英語解釋這是如何工作的(或至少爲什麼我的結構不)?我想叫我在新澤西州的servlet資源,這是我叫ExportResource,ExportLicenseInfo映射到http://example.com/myApp/export/software_licenses.{year}-{month}.{format}功能,例如:http://example.com/myApp/export/software_licenses_2013-10.csv澤西島servlet映射混淆

servlet配置在web.xml:

<servlet> 
    <servlet-name>ExportServlet</servlet-name> 
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> 

    <init-param> 
     <param-name>javax.ws.rs.Application</param-name> 
     <param-value>com.mycompany.app.ExportApplication</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

我在網上servlet映射.XML:

<servlet-mapping> 
    <servlet-name>ExportServlet</servlet-name> 
    <url-pattern>/export</url-pattern> 
</servlet-mapping> 

我的代碼以@Path註釋:

@Path("/export") 
public class ExportResource { 

    ... 

    @GET 
    @Produces({"text/csv", "application/json"}) 
    @Path("/software_licenses_{year: [0-9][0-9][0-9][0-9]}-{month: [0-1][0-9]}.{format}") 
    public String ExportLicenseInfo(...) { 
    ... 
    } 

當我嘗試訪問該資源時,我得到一個404新澤西跟蹤日誌:

Feb 21, 2014 2:41:46 PM org.glassfish.jersey.filter.LoggingFilter log 
INFO: 6 * LoggingFilter - Request received on thread http-bio-8080-exec-67 
6 > GET http://localhost:8080/app/export/software_licenses_2013-10.csv 
6 > host: localhost:8080 
6 > connection: keep-alive 
6 > cache-control: max-age=0 
6 > accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 
6 > user-agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36 
6 > accept-encoding: gzip,deflate,sdch 
6 > accept-language: en 
6 > cookie: JSESSIONID=DB64E0B066BDEE8CABFC94686AD6ACDC.test; JSESSIONIDSSO=61B51CEED61F8F6CE8A8DB46B38BAC9F; i18next=en 

Feb 21, 2014 2:41:46 PM org.glassfish.jersey.filter.LoggingFilter log 
INFO: 6 * LoggingFilter - Response received on thread http-bio-8080-exec-67 
6 < 404 
+0

你'ExportResource'不是一個Servlet 。 –

+0

是的;我知道。我的servlet是一個調用該包的球衣小服務程序。 – CullenJ

+0

哦,我得到了404。我會更新我的問題。 – CullenJ

回答

2

嘗試映射球衣的servlet是這樣的:

<servlet-mapping> 
<servlet-name>ExportServlet</servlet-name> 
<url-pattern>/export/*</url-pattern> 
</servlet-mapping> 
+2

謝謝!我剛剛完成了使用該模式的工作。在我的Servlet資源中,我還必須將類的'@ Path'註釋從''/ export''更改爲''/''。 – CullenJ