【发布时间】:2015-01-24 18:57:22
【问题描述】:
我一直在尝试使用 NetBeans Ide 创建一个简单的 Restful WebService。
我的 Java EE 版本是:Java EE 7 Web。
我创建了一个新的 Java Web 应用程序,设置了这个 ContexPath:/DukesAgeService。
现在,运行我的应用程序,浏览器显示我的Index.html 页面:
http://localhost:8080/DukesAgeService/
所以,一切正常。
然后,我尝试使用 RESTful Web 服务向导创建一个简单的 RESTful 资源。
所以,我创建了这个类:
package firstcup.webservice;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PUT;
/**
* REST Web Service
*
* @author nolanof
*/
@Path("dukesAge")
public class DukesAgeResource {
@Context
private UriInfo context;
/**
* Creates a new instance of DukesAgeResource
*/
public DukesAgeResource() {
}
/**
* Retrieves representation of an instance of firstcup.webservice.DukesAgeResource
* @return an instance of java.lang.String
*/
@GET
@Produces("text/plain")
public String getText() {
return "hello world";
}
}
但是在 url 处运行我的应用程序:
http://localhost:8080/DukesAgeService/dukesAge
我得到一个 404-not found 页面。
我预计任何传入的具有"/dukesAge" url 的get 请求都由DukesAgeResource 类getText 方法处理。怎么了?
谢谢
【问题讨论】:
-
请将您的 web.xml 文件连同项目文件夹结构一起发布
标签: java web-services rest glassfish jax-rs