一、环境
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
分享到:
相关推荐
NULL 博文链接:https://liangyingying1117.iteye.com/blog/2155855
instrumented-restful-fast-request-pro-2023.1.7.1 可用版,亲测,可用。
Building-RESTful-Python-Web-Services, 构建 RESTful python Web服务的代码库,由Packt发布 #Building RESTful python Web服务 这是构建 RESTful python Web服务 插件的代码库,由Packt发布。 它包含了从开始到结束...
Java SpringBoot 课程 restful crud 实验资源 restful 风格的增删改查
找到插件的安装目录如:C:\Users\work_\AppData\Roaming\JetBrains\IntelliJIdea2023.1\plugins\Restful Fast Request - API Buddy\lib 将附件中的jar包拖入替换. 此版本为最新版本 2023.2.1.1
提供restful风格的框架, 拥有客户端和服务端两部分, 具体实现功能代码需要自己添加。
laravel-restful-api-starter, 使用 Laravel 和MongoDB构建一个 RESTful API #Laravel Restful API启动程序现在查看一下 WIKI !欢迎捐赠对于代码和 doc: ) !是什么?这里启动器基于以下功能:Laravel 4.2: 使用轻...
Developing-Restful-Web-Services-with-Jersey-2-0
资源来自pypi官网。 资源全名:flask-restful-swagger-3-0.2.0.tar.gz
jersey构建简单的Restful服务!
SAP-BO-Restful-SDK-开发指导手册
基于 Jersey 构建 RESTful 服务。 ---------------------------------------------------- 本 PDF 基于开源文档,目录书签齐全。 版权归原作者,翻译版权归译者。 -----------------------------------------------...
RESTFUL的实现-springboot2.0版本 网址:https://blog.csdn.net/chenwewi520feng/article/details/130634490 使用一个示例来说明restful的使用,是以springboot的2.0版本作为基础的
本资源类似于 Postman 的 IDEA 插件Restful Fast Request,在IDEA安装该插件后,找到插件安装目录,【C:\\... API Buddy\\lib】替换掉里面的jar文件【instrumented-restful-fast-request-pro-2023.1.7.1.jar】即可使用
jersey是一种 restful框架,使用它为我们提供接口。有三块重要的东西,jersey-server,jersey-core, 集成(与spring等等)。
RESTful Web 服务 - 快速指南
Java使用Jersey框架构建 RESTful Web服务返回json数据所需的jar包。Jackson-core-asl.jar / Jackson-jaxrs.jar / Jackson-mapper-asl.jar / Jackson-xc.jar / jersey-media-json-Jackson.jar
使用Java创建RESTful Web Service - ImportNew1
spring boot学习的web开发课程资源 spring boot学习的web开发课程资源 spring boot学习的web开发课程资源 spring boot学习的web开发课程资源 spring boot学习的web开发课程资源 spring boot学习的web开发课程...