我正在尝试使用 Java,Rest Webservices(Jersey),Glass fish 构建简单的Web服务。项目在服务器中成功部署没有任何错误,但是当我在浏览器中访问资源时,它提供 404-Not Found Error 。
我的资源类:
package org.student.services;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/ConversionService")
public class FeetToInchAndInchToFeetConversionService {
@GET
@Path("/InchToFeet/{i}")
@Produces(MediaType.TEXT_XML)
public String convertInchToFeet(@PathParam("i") int i) {
int inch=i;
double feet = 0;
feet =(double) inch/12;
return "<InchToFeetService>"
+ "<Inch>" + inch + "</Inch>"
+ "<Feet>" + feet + "</Feet>"
+ "</InchToFeetService>";
}
@Path("/FeetToInch/{f}")
@GET
@Produces(MediaType.TEXT_XML)
public String convertFeetToInch(@PathParam("f") int f) {
int inch=0;
int feet = f;
inch = 12*feet;
return "<FeetToInchService>"
+ "<Feet>" + feet + "</Feet>"
+ "<Inch>" + inch + "</Inch>"
+ "</FeetToInchService>";
}
}
Web.xml是:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>StudentPortal</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>org.student.services</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>
</web-app>
使用以下网址与https // mylocalhost:端口/ StudentPortal /休息/ ConversionService / InchToFeet / 2
请有人指出我做错了什么