用Jersey构建RESTful服务1--HelloWorld
一、环境
1、Eclipse Juno R2
2. Tomcat 7
3. Jersey 2.7 下载地址( https://jersey.java.net/download.html)
二、流程
1.Eclipse 中创建一个 Dynamic Web Project ,本例为“RestDemo”
2.按个各人习惯建好包,本例为“com.waylau.rest.resources”

3.解压jaxrs-ri-2.7,
将api、ext、lib文件夹下的jar包都放到项目的lib下;

项目引入jar包

4.在resources包下建一个class“HelloResource”
- package com.waylau.rest.resources;
- import javax.ws.rs.GET;
- import javax.ws.rs.Path;
- import javax.ws.rs.Produces;
- import javax.ws.rs.PathParam;
- import javax.ws.rs.core.MediaType;
- @Path("/hello")
- public class HelloResource {
- @GET
- @Produces(MediaType.TEXT_PLAIN)
- public String sayHello() {
- return "Hello World!" ;
- }
- @GET
- @Path("/{param}")
- @Produces("text/plain;charset=UTF-8")
- public String sayHelloToUTF8(@PathParam("param") String username) {
- return "Hello " + username;
- }
- }
5.修改web.xml,添加基于Servlet-的部署
- <servlet>
- <servlet-name>Way REST Service</servlet-name>
- <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
- <init-param>
- <param-name>jersey.config.server.provider.packages</param-name>
- <param-value>com.waylau.rest.resources</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>Way REST Service</servlet-name>
- <url-pattern>/rest/*</url-pattern>
- </servlet-mapping>
6.项目部署到tomcat,运行
7.浏览器输入要访问的uri地址
http://localhost:8089/RestDemo/rest/hello
输出Hello World!

http://localhost:8089/RestDemo/rest/hello/Way你好吗
输出Hello Way你好吗

参考:https://jersey.java.net/documentation/latest/user-guide.html
用Jersey构建RESTful服务1--HelloWorld的更多相关文章
- 用Jersey构建RESTful服务7--Jersey+SQLServer+Hibernate4.3+Spring3.2
一.整体说明 本例执行演示了用 Jersey 构建 RESTful 服务中.怎样集成 Spring3 二.环境 1.上文的项目RestDemo 2.Spring及其它相关的jar ,导入项目 三.配置 ...
- jersey+maven构建restful服务
一.新建一个Maven Web项目 a) 新建一个简单的Maven项目 b) 将简单的Maven项目转成Web项目 (若没出现further configuration available--或里面的 ...
- 【用jersey构建REST服务】系列文章
1.用Jersey构建RESTful服务1--HelloWorld http://blog.csdn.NET/kkkloveyou/article/details/21391033 2.用Jersey ...
- Maven + Jetty + Jersey搭建RESTful服务
IntelliJ IDEA + Maven + Jetty + Jersey搭建RESTful服务 本文参考以下内容: 使用Jersey实现RESTful风格的webservice(一) Starti ...
- Springboot & Mybatis 构建restful 服务五
Springboot & Mybatis 构建restful 服务五 1 前置条件 成功执行完Springboot & Mybatis 构建restful 服务四 2 restful ...
- Springboot & Mybatis 构建restful 服务四
Springboot & Mybatis 构建restful 服务四 1 前置条件 成功执行完Springboot & Mybatis 构建restful 服务三 2 restful ...
- Springboot & Mybatis 构建restful 服务三
Springboot & Mybatis 构建restful 服务三 1 前置条件 成功执行完Springboot & Mybatis 构建restful 服务二 2 restful ...
- Springboot & Mybatis 构建restful 服务二
Springboot & Mybatis 构建restful 服务二 1 前置条件 成功执行完Springboot & Mybatis 构建restful 服务一 2 restful ...
- Springboot & Mybatis 构建restful 服务
Springboot & Mybatis 构建restful 服务一 1 前置条件 jdk测试:java -version maven测试:命令行之行mvn -v eclipse及maven插 ...
随机推荐
- POJ 3243 // HDU 2815(改下输出,加个判断)
A^x = B (mod C) 的模板题,不够要用扩展BSGS (虽然AC,但完全理解不了模板0.0,以后学好数学在来慢慢理解555555) #include <iostream> #in ...
- Android开发之多Fragment切换优化
问题分析 一直在简书里看别人的技术贴,今天我也来写点自己的心得!最近在写一个项目用到大量的Fragment后的总结! 我想刚刚接触安卓的同学或许会这么写: FragmentManager fragme ...
- HTTP协议 (1)
HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传送协议. HTT ...
- php 爬取数据
简单. 灵活.强大的PHP采集工具,让采集更简单一点. 简介: QueryList使用jQuery选择器来做采集,让你告别复杂的正则表达式:QueryList具有jQuery一样的DOM操作能力.Ht ...
- 使用super调用父类的构造方法
package com.bjpowernode.t02inheritance.c09; /* * 使用super调用父类的构造方法 */public class TestSuper02 { publi ...
- WebApi的调用-1.前端调用
前端调用 html <div class="row"> <form id="queryForm"> <input name=&qu ...
- 如何批量的在django中对url进行用户登陆限制
参考URL: https://blog.csdn.net/hanshengzhao/article/details/79540306?utm_source=blogxgwz0 1,首先定义一个内部有装 ...
- SQL行装列PIVOT和列转行UNPIVOT
数据 CREATE TABLE student( no int, ca ), name ), subject ), scorce int ); /* 数据 */ , ); , ); , ); , ); ...
- [转] Nginx 配置 SSL 证书 + 搭建 HTTPS 网站教程
一.HTTPS 是什么? 根据维基百科的解释: 超文本传输安全协议(缩写:HTTPS,英语:Hypertext Transfer Protocol Secure)是超文本传输协议和SSL/TLS的组合 ...
- 异常Cannot get a text value from a numeric cell
POI操作Excel时偶尔会出现Cannot get a text value from a numeric cell的异常错误. 异常原因:Excel数据Cell有不同的类型,当我们试图从一个数字类 ...