我正在尝试实施简单的泽西休息客户端
Message.class:
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.FormParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
@Path("/message")
public class Message {
@GET
@Path("/postmsg/{regId}/{msg}")
@Produces("text/plain")
public Response sendMsg(@PathParam("regId") String regId,@PathParam("msg") String msg) {
String output ="RegId: " + regId + ", Message: " + msg;
return Response.status(200).entity(output).build();
}
}
Web.xml中 我在My web.xml中添加了jersey依赖,如下所示。
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>jersey-servlet</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.sample.web.msg</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
的pom.xml: 我在My web.xml中添加了jersey依赖,如下所示。
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.8</version>
</dependency>
当我尝试在浏览器上运行此网址时:
http://localhost:8080/GCM/message/postmsg/regId/msg
我得到的只是 * HTTP状态404 - / GCM / message / postmsg / regId / msg *
有人可以帮助,我缺少的是什么,提前谢谢。 :)
答案 0 :(得分:1)
您的Jersey servlet已映射到/rest/*
,但您的网址以/GCM/*
开头。
将servlet映射更改为:
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/GCM/*</url-pattern>
</servlet-mapping>
或访问以下网址:
http://localhost:8080/rest/message/postmsg/regId/msg