Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java RESTful web服务未在Eclipse IDE中启动_Java_Rest_Web Services - Fatal编程技术网

Java RESTful web服务未在Eclipse IDE中启动

Java RESTful web服务未在Eclipse IDE中启动,java,rest,web-services,Java,Rest,Web Services,我已经用JAVA编写了一个简单的RESTful web服务,但是当我使用Eclipse IDE中的run As-->run on server选项运行它时,我得到了HTTP状态404–Not Found错误。请告诉我代码中可能存在的问题 响应: web.xml <?xml version="1.0" encoding="UTF-8"?> <!--?xml version="1.0" encoding="UTF-8"?--> <web-app xmlns:xsi="

我已经用JAVA编写了一个简单的RESTful web服务,但是当我使用Eclipse IDE中的run As-->run on server选项运行它时,我得到了
HTTP状态404–Not Found
错误。请告诉我代码中可能存在的问题

响应:

web.xml

<?xml version="1.0" encoding="UTF-8"?> <!--?xml version="1.0" encoding="UTF-8"?-->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>RESTfulWebServiceExample</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>org.arpit.javapostsforlearning.webservice</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> 

您试图转到
localhost:8080/restfulwebservicecample
时,根据您的
web.xml
restfulwebservicecample是您的显示名称。您需要转到
localhost:8080/rest/
点击servlet上下文根目录(如
web.xml
的servlet映射部分所定义)。

如果下面的解决方案为您的问题提供了答案,您能选择它作为正确答案吗?
package org.arpit.javapostsforlearning.webservice;

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 ""
        + "" + inch + ""
          + "" + feet + ""
         + "";
      }

      @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 ""
            + "" + feet + ""
            + "" + inch + ""
            + "";
      }
}