什么是泽西过滤器?
我想基本上了解 Jersey 过滤器是什么以及它与 servlet 过滤器有何关系?它们是一样的吗?泽西过滤器的主要使用模式有哪些?
I want to know basically what a Jersey filter is and how is it related to a servlet filter? Are they the same? What are the main patterns of using a Jersey Filter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从技术上讲,Jersey 过滤器不是 servlet 过滤器。但是,您可以将 Jersey 过滤器用于许多与使用 servlet 过滤器相同的事情 - 影响 Jersey 公开的所有(或部分或大多数)服务的横切关注点。
正如前面的答案所述,Jersey 带有两个过滤器,但您可以有效地实现 Jersey 接口
ContainerRequestFilter
或/和ContainerResponseFilter
(如果您不想扩展它们)。你并不局限于这两个。另一个需要记住的 Jersey 接口是
ResourceFilter
- 可以为仅影响某些服务的过滤器实现此接口。Technically, a Jersey filter is not a servlet filter. However, you can use a Jersey filter for many of the same things that you would use a servlet filter for - cross-cutting concerns that affect all (or some, or most) the services that Jersey exposes.
As the previous answer states, Jersey comes with two filters, but you can usefully implement the Jersey interfaces
ContainerRequestFilter
or/andContainerResponseFilter
if you don't want to extend them. You're not limited to these two.Another Jersey interface to keep in mind is
ResourceFilter
- this interface can be implemented for a filter that affects only some of the services.您问题的第一部分可以在 泽西岛文档。 Jersey 过滤器与 servlet 过滤器不同。
Jersey 中包含两个过滤器,一个用于记录请求的过滤器,一个用于压缩 (GZip) 的过滤器。
自定义过滤器的另一个用例是身份验证或授权。
The first part of your question may be answered in the Jersey documentation. A Jersey filter is not the same as a servlet filter.
There are two filters included in Jersey, a filter for logging requests and one for compression (GZip).
Another use case for a custom filter would be authentication or authorization.