我试图通过JAX-RS Web服务发送JSON对象.我的文件web.xml是:
<servlet>
<description>JAX-RS Tools Generated - Do not modify</description>
<servlet-name>JAX-RS Servlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>it.notifire</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JAX-RS Servlet</servlet-name>
<url-pattern>/jaxrs/*</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
模拟我要发送的对象的类是:
public class GPSCoordinate {
private float latitudine;
private float longitudine;
public float getLatitudine() {
return latitudine;
}
public void setLatitudine(float latitudine) {
this.latitudine = latitudine;
}
public float getLongitudine() {
return longitudine;
}
public void setLongitudine(float longitudine) {
this.longitudine = longitudine;
}
}
Run Code Online (Sandbox Code Playgroud)
根类资源是:
@Path("position")
public class Position {
@Context
private …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用JAX-RS创建和部署RESTful Web服务并将其部署到tomcat.我不想使用任何IDE.在Tomcat中,我在webapps中有以下目录结构
notifire\WEB-INF\
|
---> web.xml
|
---> \classes/Notifier.class
|
---> \lib\javax.ws.rs-api-2.0
Run Code Online (Sandbox Code Playgroud)
我的web.xml包含:
<servlet>
<servlet-name>Web Service Servlet</servlet-name>
<servlet-class>javax.ws.rs.core.Application</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Web Service Servlet</servlet-name>
<url-pattern>/webservice/*</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
并且从文件Notifier.class中编译了类文件Notifier.java.
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
@Path("notifier")
public class Notifier {
@Context
private UriInfo context;
@GET
@Produces("text/html")
public String getHTML() {
return "<p></p>";
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试访问Web服务时,http://localhost:8080/notifire/webservice/notifier我收到以下错误:
--type异常报告
--message类javax.ws.rs.core.Application不是Servlet
--description服务器遇到内部错误,导致无法完成此请求.
任何帮助表示赞赏.