【发布时间】:2013-10-27 16:40:07
【问题描述】:
在 Tomcat 和 Jersey 库下,我创建了本课程中描述的 REST Web 服务:
package Servicios;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.PathParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
@Path("service")
public class ServiceResource {
@Context
private UriInfo context;
/**
* Creates a new instance of ServiceResource
*/
public ServiceResource() {
}
@GET
@Produces("text/html")
public String getHtml() {
return "<h1>Here we are, at the contemplation of the most simple web service</h1>";
}
@PUT
@Consumes("text/html")
public void putHtml(String content) {
}
}
所以,正如我在访问 http://localhost:8080/GetSomeRest 之前设置的那样,会创建默认创建的 .jsp 文件。
我在项目属性(使用 NetBeans)中将一个 相对 URL 设置为webresources/service,因此service 部分与@Path("service") 中的定义相同。一切正常,转到http://localhost:8080/GetSomeRest/webresources/service 会使用 Web 服务。
但是,如果我想直接从http://localhost:8080/GetSomeRest/service使用该服务怎么办?我试图在这样的相对 URL 中只设置 service,然后我收到了一条 Error 404 消息去 http://localhost:8080/GetSomeRest/service
虚拟路径如何工作?
向 Web 服务添加别名意味着什么?
【问题讨论】:
-
我不清楚你在问什么。您是在问相对 URL 是如何工作的吗?您是否在问如何在您的 Web 服务中设置别名?这很混乱。