RESTful WebService入门

来源:互联网 发布:域名到期如何续费 编辑:程序博客网 时间:2024/05/17 01:53
import com.sun.jersey.api.container.httpserver.HttpServerFactory; 
import com.sun.net.httpserver.HttpServer; 
import javax.ws.rs.GET; 
import javax.ws.rs.Path; 
import javax.ws.rs.Produces; 
import java.io.IOException; 
//指定URI 
@Path("/helloworld") 
public class HelloWorld { 
        //处理HTTP的GET请求 
        @GET 
        // 处理请求反馈的内容格式为"text/plain" 
        @Produces("text/plain") 
        public String getClichedMessage() { 
                return "Hello World!"; 
        } 
        public static void main(String[] args) throws IOException { 
                //创建RESTful WebService服务 
                HttpServer server = HttpServerFactory.create("http://192.168.67.28:9999/"); 
                //启动服务,这会导致新开一个线程 
                server.start(); 
                //输出服务的一些提示信息到控制台 
                System.out.println("RESTful WebService服务已经启动"); 
                System.out.println("服务访问地址: http://192.168.67.28:9999/helloworld"); 
        } 

}


<!-- restful jar -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.19</version>
</dependency>
<!-- restful jar -->



0 0