JAX-RS是否建立在Servlet API之上?如何? [英] Is JAX-RS built on top of Servlet API? How?

查看:506
本文介绍了JAX-RS是否建立在Servlet API之上?如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读JAX-RS是建立在servlet之上的.从字面上看这是正确的,还是仅意味着它是更高级别的组件?如果是的话,那是如何工作的? JAX-RS是否创建一个Servlet来解析请求并手动初始化@Path带注释的类并将修改后的参数传递给它们? JSR似乎没有指定这一点,并且没有任何提及它的书有任何细节.

I've been reading that the JAX-RS is built on top of servlets. Is this literally true, or it just mean that it is a higher level component? If it is, how does that work? Does JAX-RS create a servlet which parses the request and manually initializes @Path annotated classes and passes the modified parameters to them? The JSR does not seem to specify this, and none of the books that mention it go into any details.

注意:我没有部署JAX或servlet的麻烦,我只是对细节感到好奇,因为它可以更好地了解Web容器的工作原理.

note: I don't have trouble deploying JAX or servlets, I am just curious about the details, as it would provide a better understanding of how the web container works.

推荐答案

我一直在阅读JAX-RS是建立在servlet之上的.这是真的吗?

I've been reading that the JAX-RS is built on top of servlets. Is this literally true,

简而言之,是的,JAX-RS规范建立在Servlet以及任何其他部署方法(例如 @Jilles van Gurp )是实现特定的.

Simply put, YES, the JAX-RS specification is built on top of Servlets, and any other deployment method (such as mentioned by @Jilles van Gurp) is implementation specific.

JAX-RS是否创建一个Servlet来解析请求并手动初始化@Path注释类并将修改后的参数传递给它们?

Does JAX-RS create a servlet which parses the request and manually initializes @Path annotated classes and passes the modified parameters to them?

JAX-RS不执行任何操作.实施入口点servlet的是实施(例如Jersey,RESTEasy,CXF).实现是否需要显式解析请求?不,不是全部.大部分内容都是由servlet容器处理的.主要是实现只需要解析请求 body (因为"request"所隐含的不仅仅是主体,例如URL,标头).

JAX-RS doesn't do anything. It's the implementation (e.g. Jersey, RESTEasy, CXF) that implements the entry point servlet. Does the implementation need to explicitly parse the request? No, not all of it. Most of that stuff is handled by the servlet container. Mainly the implementation will just need to parse the request body (as "request" implies more than just the body, e.g URL, headers).

基本上,与JAX-RS相关的所有事情都由实现来处理. Servlet容器除了传递HttpServletRequest和HttpServletResponse外,什么都没有,就像您要实现自己的Servlet一样.如果要创建自己的JAX-RS实现,则将HttpServletRequest(Response)传递给您的servlet是请求入口点,而其他一切都取决于您.

Basically, everything related to JAX-RS is handled by the implementation. The servlet container has nothing to with anything but passing the HttpServletRequest and HttpServletResponse, just like if you were to implement your own servlet. If you were to make your own JAX-RS implementation, the servlet passing you the HttpServletRequest(Response) is the request entry point, and everything else is up you.

请求"一词的含义不仅限于正文,例如, URL

错误的例子.实际上,JAX-RS实现解析URL以获取路径参数和查询参数.尽管Servlet容器将解析URL并将查询参数添加到HttpServletRequest参数映射中,但是该映射也具有表单POST参数,因此实现也需要自己对查询参数进行解析.

Bad example. Actually, the JAX-RS implementation would parse the URL in order to get path parameters and query parameters. Though the Servlet container will parse the URL and add query parameters to the HttpServletRequest parameters map, that map also has form POST parameters, so the implementation will need to do it's own parsing of the query parameters also.

这篇关于JAX-RS是否建立在Servlet API之上?如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆