2013-02-19 155 views
0

我的Tomcat服務器是不是100%與其他人一樣,我試圖按照本教程:在我奇怪的Tomcat服務器上獲取RESTful Web服務?

​​

到目前爲止,我已經下載:

asm-3.3.1.jar 
jersey-client-1.17.jar 
jersey-core-1.17.jar 
jersey-server-1.17.jar 

並把它們放在我的/ lib /目錄。

我的文件夾結構是這樣的:

/WEB-INF/classes/rest/com/mkyong/HellowWorldService.class 

我有我的web.xml中定義爲:

<display-name>Restful Web Application</display-name> 

<servlet> 
    <servlet-name>jersey-serlvet</servlet-name> 
    <servlet-class> 
       com.sun.jersey.spi.container.servlet.ServletContainer 
      </servlet-class> 
    <init-param> 
     <param-name>com.sun.jersey.config.property.packages</param-name> 
     <param-value>com.mkyong.rest</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>jersey-serlvet</servlet-name> 
    <url-pattern>/servlets/servlet/rest/*</url-pattern> 
</servlet-mapping> 

我不知道該URL模式是正確的?

當我訪問myserver.com/servlets/servlet/rest/hello/Eric我應該得到它說澤西說:埃裏克,而是我得到一個HTTP狀態500錯誤:

http://pastebin.com/iq5NDVw4

Tomcat的日誌中說:

Feb 19, 2013 4:46:21 PM com.sun.jersey.api.core.PackagesResourceConfig init 
INFO: Scanning for root resource and provider classes in the packages: 
    com.mkyong.rest 
Feb 19, 2013 4:46:21 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate 
INFO: Initiating Jersey application, version 'Jersey: 1.17 01/17/2013 04:27 PM' 
Feb 19, 2013 4:46:21 PM com.sun.jersey.server.impl.application.RootResourceUriRules <init> 
SEVERE: The ResourceConfig instance does not contain any root resource classes. 
Feb 19, 2013 4:46:27 PM com.sun.jersey.api.core.PackagesResourceConfig init 

任何幫助大受好評!

編輯:

我發現的傢伙頁面上this article。但它沒有多大意義。

+0

嘗試添加像球衣,servlet的1.17.jar所有.jar文件? – sschrass 2013-02-19 17:17:03

+0

我在Jersey頁面上沒有看到一個叫做那個的頁面。想想也許他們不再使用它了? http://jersey.java.net/nonav/documentation/latest/chapter_deps.html – 2013-02-19 17:18:21

+1

我一直使用http://maven.java.net/service/local/artifact/maven/redirect?r= release&g = com.sun.jersey&a = jersey-archive&v = 1.17&e = zip – sschrass 2013-02-19 17:23:11

回答

1

相當於本教程http://www.vogella.com/articles/REST/article.html#installation

This name is derived from the "display-name" defined in the web.xml file, augmented with the servlet-mapping url-pattern and the "hello" @Path annotation from your class file.

根據這一點,你的情況display-nameweb.xml" "和你用於測試的鏈路沒有提及。

編輯: 這個servlet的基本網址是:

http://your_domain:port/display-name/url-pattern/path_from_rest_class 
+0

我把它設置爲 Restful Web Application,所以我應該把它放在URL中? – 2013-02-19 17:25:07

+1

myserver.com/Restful Web Application/servlets/servlet/rest/hello/Eric – sschrass 2013-02-19 17:25:48

+1

刪除顯示名稱中的那些「」 – sschrass 2013-02-19 17:26:06

0

看看tomcat日誌。也許你應該在/ WEB-INF/lib或/ tomcat/lib目錄下放置一些jar庫。也許一些庫在運行時使用。仔細閱讀tomcat日誌。