使用Jersey开发Resful的web Service的hello world
来源:互联网 发布:js new date精确到秒 编辑:程序博客网 时间:2024/05/29 17:10
RESTful Web 服务简介
REST 在 2000 年由 Roy Fielding 在博士论文中提出,他是 HTTP 规范 1.0 和 1.1 版的首席作者之一。
REST 中最重要的概念是资源(resources),使用全球 ID(通常使用 URI)标识。客户端应用程序使用 HTTP 方法(GET/ POST/ PUT/ DELETE)操作资源或资源集。RESTful Web 服务是使用 HTTP 和 REST 原理实现的 Web 服务。通常,RESTful Web 服务应该定义以下方面:
Web 服务的基/根 URI,比如 http://host/<appcontext>/resources。
支持 MIME 类型的响应数据,包括 JSON/XML/ATOM 等等。
服务支持的操作集合(例如 POST、GET、PUT 或 DELETE)。
构建 RESTful Web 服务
@Path("/hello")
public class HelloResource
{
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayHello(){
return "hello jersey";
}
}
web.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>
com.sun.jersey.spi.container.servlet.ServletContainer
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>所需jar包
jersey-core.jar,jersey-server.jar,jsr311-api.jar,asm.jar
客户端测试所需包,jersey-client.jar,junit-4.1.jar
测试:
网页上访问:http://localhost:8080/RestHello/rest/hello
网页上显示
hello jerseyJunit测试,@Test
public void getTest(){
Client c = Client.create();
WebResource hello = c.resource("http://localhost:8080/RestHello/rest/hello");
String s = hello.get(String.class);
System.out.println(s);
}打印”hello jersey“
- 使用Jersey开发Resful的web Service的hello world
- Web Service, Hello World
- CXF Web Service的Hello World之一 搭建环境
- spring下的resful接口开发
- maven工程的Jersey Web Service
- 使用Maven和Jersey Framework开发REST风格Web Service
- Jersey hello world example
- Plasma开发的“Hello World”
- 使用jgraph的“Hello world!"
- Jersey—— 一个基于Rest风格的Web Service开发框架
- 使用MyEclipse开发Struts框架的Hello World!(录像1)
- 使用MyEclipse开发Struts框架的Hello World!(录像2)
- Python初学,web.py的Hello World
- Web Service(一):Hello World
- cxf 之 Hello World Web Service
- Jersey+Spring+Hibernate搭建的一个简单Web Service
- jersey restful服务Hello World
- 使用 Jersey + Tomcat 輕鬆開發 RESTful Web Service
- 设计模式 Command real-world
- 11款用于优化、分析源代码的Java工具
- 发现jsf + spring在jboss中的一个问题
- 查找 HBox 下面的 为CheckBox的子元素,
- 自定义struts2验证框架的错误信息样式
- 使用Jersey开发Resful的web Service的hello world
- 工作英文
- http://fuliang.iteye.com/blog/69313
- awk的类sql数据处理
- override 之1.5 与1.6
- awk的多文件处理
- 很有用的shell / python 脚本片段(记录)
- 分享非常有用的Java程序 (关键代码) (二)---列出文件和目录
- 什么是OGG-----HTML5知识点