我UBUNTU 下運行我的TomCat7與Eclipse項目我試圖遵循在線教程創建一個RESTful API。我遵循完全相同的步驟,但是當我嘗試運行該項目時遇到了404錯誤。錯誤404 - 請求的資源不是服務現有的Eclipse Tomcat7
這裏是我的.class文件是在src文件夾
package com.eviac.blog.restws;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
/**
*
* @author pavithra
*
*/
// @Path here defines class level path. Identifies the URI path that
// a resource class will serve requests for.
@Path("UserInfoService")
public class UserInfo {
// @GET here defines, this method will method will process HTTP GET
// requests.
@GET
// @Path here defines method level path. Identifies the URI path that a
// resource class method will serve requests for.
@Path("/name/{i}")
// @Produces here defines the media type(s) that the methods
// of a resource class can produce.
@Produces(MediaType.TEXT_XML)
// @PathParam injects the value of URI parameter that defined in @Path
// expression, into the method.
public String userName(@PathParam("i") String i) {
String name = i;
return "<User>" + "<Name>" + name + "</Name>" + "</User>";
}
@GET
@Path("/age/{j}")
@Produces(MediaType.TEXT_XML)
public String userAge(@PathParam("j") int j) {
int age = j;
return "<User>" + "<Age>" + age + "</Age>" + "</User>";
}
}
這是web.xml文件是在WEB-INF - > lib中
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>RESTfulWS</display-name>
<servlet>
<servlet-name>Jersey REST Service</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.eviac.blog.restws</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
當我嘗試訪問這從localhost,我得到錯誤..
所請求的資源(/ RESTfulWS /)不可用。
在什麼情況下路徑在部署這個Web應用程序? –
@MarkThomas,我的Tomcat部署的安裝文件夾中的/ opt/tomcat的。當我去的config/server.xml中,我可以看到我的應用程序,其中: '<上下文的docBase =「/選擇/ tomcat的/ wtpwebapps/RESTfulWS」路徑= 「/ RESTfulWS」 重新加載= 「真實」 來源= 「org.eclipse.jst.jee.server:RESTfulWS」/>' – Suvimo
如果你請求/ RESTfulWS/REST /? –