如果您的 web.xml 和服务类映射如下,它应该可以正常工作:
你的网址:
http://localhost:8080/RestFulWS/rest/exampleWithOutParam/getName
网页.xml:
<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.yourapp</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>
您的服务:
package com.yourapp;
// imports here
@Path("/exampleWithOutParam")
public class YourService {
@GET
@Path("/getName")
@Produces("text/plain")
public Response getName() {
return Response.ok("OK").build();
}
}