簡體   English   中英

如何發布“ Hello world” Rest Web服務?

[英]How to publish “Hello world” Rest web service?

package my.first.rest;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("hello")
public class Hello {

  // This method is called if TEXT_PLAIN is requested
  @GET
  @Produces(MediaType.TEXT_PLAIN)
  public String sayHelloInPlainText() {       
    return "Hello world!";
  }
 http://stackoverflow.com/questions/2893796/create-hello-world-with-restful-web-service-and-jersey
  // This method is called if HTML is requested
  @GET
  @Produces(MediaType.TEXT_HTML)
  public String sayHelloInHtml() {
    return "<html> " + "<title>" + "Hello world!" + "</title>"
        + "<body><h1>" + "Hello world!" + "</body></h1>" + "</html> ";
  }
}

這是我寫的Web服務Restful的代碼。 當我使用Test Client發布時,就會出現此錯誤:

IWAB0489E Error when deploying Web service to Axis runtime
  axis-admin failed with  {http://schemas.xmlsoap.org/soap/envelope/}
  Server.userException java.net.ConnectException: Connection refused: connect

我該如何解決? 這僅與Rest一起提供,而不與SOAP一起提供。

您必須下載jersey [來自sunmicrosystem的REST的實現],並將這些jar包含在您的應用程序中,除此之外,您還必須相應地修改web.xml。
網上有多個初學者教程- 單擊此處

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM