ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
# JAX-RS 2.0 教程 > 原文: [https://howtodoinjava.com/restful-web-service/](https://howtodoinjava.com/restful-web-service/) **JAX-RS 2.0** 是一个旨在帮助您在客户端和服务器端编写 RESTful 应用的框架。 以下教程是使用 **RESTEasy** 框架构建的。 在 [Jersey](//howtodoinjava.com/jersey-jax-rs-tutorials/) 和 [Dropwizard](//howtodoinjava.com/dropwizard-tutorials/) 页面上获得更多 **JAX-RS 教程**。 ## HelloWorld 应用 #### [RESTEasy + JBOSS 7 HelloWorldd 应用](//howtodoinjava.com/resteasy/resteasy-jboss-7-hello-world-application/ "RESTEasy + JBOSS 7 HelloWorld application") 了解在 JBOSS AS7 中构建 RESTful Web 应用所需的最基本配置。 #### [RESTEasy + Tomcat HelloWorld 应用](//howtodoinjava.com/resteasy/resteasy-tomcat-hello-world-application/ "RESTEasy + Tomcat HelloWorld application") 了解使用 Tomcat 服务器构建 RESTful Web 应用所需的最低配置。 ## REST 客户端 #### [使用`java.net`包的 RESTful 客户端](//howtodoinjava.com/resteasy/restful-webservices-client-using-java-net-package/ "testful client using java.net package") 使用`java.net package`构建 Restful 客户端以使用 Restful API。 #### [RESTEasy 客户端示例](//howtodoinjava.com/resteasy/resteasy-client-for-consuming-rest-apis/ "RESTEasy client for consuming REST APIs") 使用内置的 jax-rs 功能构建 RESTful 客户端以使用 RESTful API。 #### [Apache HttpClient 示例](//howtodoinjava.com/apache-commons/jax-rs-restful-client-using-apache-httpclient/ "JAX-RS RESTful client using apache httpclient") 使用 apache http 客户端框架构建 Restful 客户端以使用 Restful API。 #### [Ajax/JavaScript 客户端示例](//howtodoinjava.com/resteasy/resteasy-javascriptajax-client-demo/ "RESTEasy javascript/ajax client demo") 学习构建 resteasy ajax 客户端 #### [JAX-RS 2.0 客户端 API 示例](//howtodoinjava.com/resteasy/jax-rs-2-0-resteasy-3-0-2-final-client-api-example/ "JAX-RS 2.0 RESTEasy 3.0.2.Final Client API example") JAX-RS 2.0 在以前的版本中带来了很多改进。 主要改进之一是客户端 API,它在 JAX-RS 1.0 中完全丢失。 在本教程中学习使用。 ## XML / JSON 支持 #### [RESTEasy + JAXB xml 示例](//howtodoinjava.com/resteasy/resteasy-jaxb-xml-example/ "RESTEasy + JAXB xml example") 学习使用 JAXB 在 XML 文档中封送模型对象,并将其作为服务器响应发送给客户端 #### [RESTEasy + Jettison json 示例](//howtodoinjava.com/resteasy/resteasy-jettison-json-example/ "RESTEasy + Jettison json example") 使用 Jettison 学习在 JSON 文档中封送模型对象,并将其作为服务器响应发送给客户端 #### [RESTEasy + Jackson JSON 示例](//howtodoinjava.com/2013/05/10/resteasy-jackson-json-example/ "RESTEasy + Jackson JSON example") 学习使用 Jackson 封送 JSON 文档中的模型对象,并将其作为服务器响应发送给客户端 ## 文件下载/上传 #### [RESTEasy + 文件下载示例](//howtodoinjava.com/resteasy/resteasy-file-download-example/ "RESTEasy + File download example") 此示例显示了使用 RESTful API 下载各种文件格式所需的配置和代码 #### [RESTEasy + 文件上传 + HttpClient 纯 Java 客户端示例](//howtodoinjava.com/resteasy/jax-rs-resteasy-file-upload-httpclient-example/ "JAX-RS RESTEasy file upload + httpclient example") 使用纯 Java 客户端将文件上传到服务器 #### [RESTEasy + 文件上传 + HTML 表单示例](//howtodoinjava.com/resteasy/jax-rs-resteasy-file-upload-html-form-example/ "JAX-RS RESTEasy file upload + html form example") 使用 html 表单提交将文件上传到服务器 ## 注解用法和示例 #### [基于 JAX-RS `@Path`正则表达式的 URI 匹配](//howtodoinjava.com/resteasy/jax-rs-path-regex-based-uri-matching/ "@Path example") 使用`@Path`注解的 API 路径匹配示例。 还包括一些正则表达式示例。 ## Hateoas 实现 #### [RESTful Web 服务的 HATEOAS 示例](//howtodoinjava.com/resteasy/writing-restful-webservices-with-hateoas-using-jax-rs-and-jaxb-in-java/ "How to write RESTful web services using jax-rs and jaxb in java [HATEOAS example]") 学习启用 HATEOAS 链接来制作 RESTful Web 服务 ## JAX-RS 安全 #### [使用`PreProcessorInterceptor`的基本认证和授权示例](//howtodoinjava.com/resteasy/jax-rs-resteasy-basic-authentication-and-authorization-tutorial/ "JAX-RS RESTEasy basic authentication and authorization tutorial") 使用`PreProcessorInterceptor`实现安全性。 #### [JAX-RS 2.0 RESTEasy 3.0.2.Final 使用`ContainerRequestFilter`的安全性示例](//howtodoinjava.com/resteasy/jax-rs-2-0-resteasy-3-0-2-final-security-tutorial/ "JAX-RS 2.0 RESTEasy 3.0.2.Final security tutorial") `PreProcessorInterceptor`和`PostProcessorInterceptor`现在已过时。 因此,从现在开始,使用`ContainerRequestFilter`和`ContainerReponseFilter`。 在本教程中学习使用它们。 #### [REST 安全性指南](//howtodoinjava.com/security/restful-web-services-security-guide/) 保护 RESTful Web 服务的知识与编写它们一样重要。 编写安全的 API 以保护业务非常重要。 但是在开始保护 RESTful API 之前,让我们了解作为开发人员我们有哪些选择? 什么将最适合我们的用例? ## 请求验证 #### [使用 Ajax 自定义 HTML 表单](//howtodoinjava.com/resteasy/jax-rs-custom-validation-example-using-ajax/ "JAX-RS custom validation example using ajax") 为您的网页构建 Ajax 支持的 html 表单验证功能 #### [Hiberate 验证器供应器演示](//howtodoinjava.com/resteasy/resteasy-bean-validation-using-hibernate-validator-provider/ "RESTEasy bean validation using hibernate validator provider") 将 Hiberate bean 验证功能集成到您的 RESTEasy API 中 ## 各种整合 #### [使用 Spring 3 mvc 的 RESTful Web 服务](//howtodoinjava.com/spring/spring-restful/how-to-write-restful-webservices-using-spring-3-mvc/) 了解如何使用 Spring 3 框架编写 RESTful Web 服务 ## 日志支持 #### [RESTEasy + Log4j 示例](//howtodoinjava.com/log4j/resteasy-tomcat-7-log4j-logging-example/ "RESTEasy + Tomcat 7 + Log4j logging example") 在 RESTEasy 应用中添加 log4j 日志记录支持的演示配置 #### [RESTEasy + SLF4j 示例](//howtodoinjava.com/resteasy/resteasy-tomcat-7-slf4j-logging-example/ "RESTEasy + Tomcat 7 + SLF4J logging example") 演示配置以在 RESTEasy 应用中添加 slf4j 日志支持 ## 最佳实践 #### [使用`ResteasyProviderFactory`共享上下文数据](//howtodoinjava.com/resteasy/share-context-data-with-jax-rs-resteasyproviderfactory/ "Share context data with JAX-RS ResteasyProviderFactory") 当您想在应用的各个层中共享某些数据而不将其作为方法参数传递时,`ResteasyProviderFacory`可以证明非常方便 #### [使用自定义异常映射器进行异常处理](//howtodoinjava.com/resteasy/exception-handling-in-jax-rs-resteasy-with-exceptionmapper/ "Exception handling in JAX-RS RESTEasy with ExceptionMapper") 构建自定义异常映射器以处理各种异常的应用特定处理 #### [启用 gzip 压缩内容编码](//howtodoinjava.com/resteasy/enable-gzip-compression-content-encoding-in-resteasy/ "Enable gzip compression content encoding in RESTEasy") JAX-RS Resteasy 具有自动 GZIP 解压缩支持。 学习使用它。 #### [带有 ETag 示例的 JAX-RS RESTEasy 缓存控制](//howtodoinjava.com/2013/06/05/jax-rs-resteasy-cache-control-with-etag-example/ "JAX-RS RESTEasy Cache control with ETag example") **ETags** 或实体标签是有用的 HTTP 标头,可通过最小化系统上的服务器负载来帮助构建超快速的应用。 ETag 设置为对客户端的响应,因此客户端可以对条件请求使用各种控制请求标头,例如`If-Match`和`If-None-Match`。 `javax.ws.rs.core.Response.ResponseBuilder#tag`和`javax.ws.rs.core.EntityTag`是用于处理 **ETags** 的有用类。 ## RESTful Web 服务的资源 * [Jboss RESTEasy 主页](http://resteasy.jboss.org/ "reasteasy") * [JBoss 服务器](http://jbossas.jboss.org/) * [Tomcat 服务器](https://tomcat.apache.org/) * [JAX-RS 2 规范](https://jax-rs-spec.java.net/) * [Jettison 库](https://github.com/codehaus/jettison) * [Jackson 库](https://github.com/FasterXML/jackson)