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> ";
}
}
这是我编写的网络服务Restful的代码。 当我使用测试客户端发布时,会出现此错误:
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 包含在你的应用程序中,除此之外,你必须相应地修改你的网络.xml。
网上有多个初学者教程 - 点击这里