过滤器一般常用的功能

来源:互联网 发布:jsp企业门户网站源码 编辑:程序博客网 时间:2024/05/21 18:37

在我们日常开发中,新建一个项目的时候一般都会添加过滤器,进行对来自外部的请求进行一些预处理或者过滤,那么对于过滤器我们可以做哪些功能呢?

我们可以直接看过滤器的api:
Filter
A filter is an object that performs filtering tasks on either the request to a resource (a servlet or static content), or on the response from a resource, or both.

Filters perform filtering in the doFilter method. Every Filter has access to a FilterConfig object from which it can obtain its initialization parameters, a reference to the ServletContext which it can use, for example, to load resources needed for filtering tasks.

Filters are configured in the deployment descriptor of a web application

Examples that have been identified for this design are
1) Authentication Filters
2) Logging and Auditing Filters
3) Image conversion Filters
4) Data compression Filters
5) Encryption Filters
6) Tokenizing Filters
7) Filters that trigger resource access events
8) XSL/T filters
9) Mime-type chain Filter

英文不及格直接百度翻译:
滤波器
过滤器是一个对象,它对资源(servlet或静态内容)的请求执行过滤任务,或对资源的响应,或两者都执行过滤任务。
滤波器进行滤波的doFilter方法。每个过滤器已获得从它可以获得它的初始化参数的filterconfig对象,参照ServletContext它可以使用,例如,加载过滤任务所需要的资源。
过滤器配置在Web应用程序的部署描述符中。
为这种设计确定的示例是
1)身份验证过滤器
2)日志和审计过滤器
3)图像转换滤镜
4)数据压缩滤波器
5)加密过滤器
6)标记过滤器
7)触发资源访问事件的过滤器
8)XSL / T过滤器
9)MIME类型链式过滤器

这里面有9个可以用的功能,当然可能还可以实现其他功,以后遇到会更新上去

原创粉丝点击