加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

RESTful WebService入门

发布时间:2020-12-16 22:29:11 所属栏目:安全 来源:网络整理
导读: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("/
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 -->


(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读