如果您的 Web. xml 和服务类地图如下, 它应该正常工作 :
你的url:
http://localhost:8080/RestFulWS/rest/exampleWithOutParam/getName
Web.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();
}
}