有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java从HTML调用REST web服务

package com.leadwinner;

import javax.ws.rs.GET;  
import javax.ws.rs.POST;
import javax.ws.rs.Path;  
import javax.ws.rs.PathParam;  
import javax.ws.rs.Produces;  
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;  

@Path("ServiceProvider2")  
public class ServiceProvider2 {  
 @GET  
 @Path("/InchToFeet")  
  @Produces(MediaType.TEXT_XML)  
  public String convertInchToFeet(@QueryParam("i") int i) {  

    int inch=i;  
    double feet = 0;  
    feet =(double) inch/12;  

    return "<InchToFeetService>"  
    + "<Inch>" + inch + "</Inch>"  
      + "<Feet>" + feet + "</Feet>"  
     + "</InchToFeetService>";  
  }  


}

以下URL以XML形式返回结果:

/SampleTest/ServiceProvider2/InchToFeet?i=2

这很好,但当我尝试使用tomcat server运行HTML文件时,我会出现以下错误:

webpage not found 404 html files not running in restful web services using jersey


共 (0) 个答案