拦截器或过滤器 [英] Interceptors Or Filters

查看:125
本文介绍了拦截器或过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Spring Application,在其中我要进行一些安全性检查,例如文件的MD5检查,DB检查,应用程序版本检查等.

I am working on an Spring Application in which I want to do some security checks like MD5 checking of files, DB checking, Application version check etc.

我已经阅读了有关拦截器和过滤器的信息,但对于使用哪种拦截器还是有些困惑.

I have read about Interceptors and Filters but still a bit confuse about which one is good to use.

无论我阅读了什么文档,都指定过滤器和拦截器都可以用于日志记录和审计,因此哪种情况最适合这种情况. 还可以配置所有这些安全检查(文件的MD5检查,DB检查,应用程序版本检查),表示允许DB检查,同样允许应用程序版本检查.

Whatever documents I have read, it is specified that filters and interceptors both can be used for Logging and auditing so which one is good for this scenario. Also all this security checks (MD5 checking of files, DB checking, Application version check) can be configured means DB check is allow, Application version check is allow likewise.

推荐答案

在我看来,过滤器和拦截器之间的最大区别之一是:

In my opinion one of the biggest difference between Filters and Interceptors is:

过滤器仅在J2EE Web应用程序中起作用,不能在应用程序服务器之外使用,拦截器可以在不同的组件中工作并且不依赖于Web层,因此摘要拦截器比过滤器具有更广阔的领域. 如果您打算将某些组件移出容器,则应考虑使用拦截器.

Filter works only in J2EE web applications, you can not use outside of the application servers, Interceptors can work in different components and not depends on the web layer, in summary interceptor have a wide field than filters. If you are planning to move some component outside the container, you should consider use interceptors.

过滤器在请求/响应域中的工作更多,另一方面,拦截器在方法执行域中的工作更多.

Filters work more in the request/response domain, in the other hand interceptor act more in the method execution domain.

如果您需要执行可能会影响应用程序请求或响应的操作(例如日志记录,安全性,审核),或者会影响其上的数据,那么您可以选择过滤器,不要忘记插入功能这些提供.

If you need to do something that could affect the request or response to your application such as logging, security, audit, or you will affect the data coming on them, your option is filter, don't forget the plug ability that those provides.

拦截器与Java EE托管类结合使用以 允许开发人员在关联目标上调用拦截器方法 类,以及方法调用或生命周期事件

Interceptors are used in conjunction with Java EE managed classes to allow developers to invoke interceptor methods on an associated target class, in conjunction with method invocations or lifecycle events

这篇关于拦截器或过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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