Filter学习笔记
Filter Definition
Filter Function
-
user requset authentification
-
encode transformation
-
user data filter and replacement
-
picture format tranform
-
response content compress
FilterChain Call Sequence
-
When 2 filter have different url pattern,they will work with no conflict.
-
When some Filter has same url pattern ,it will be called as the order when defiend in the web.xml.
-
The user request will handed to the following filter when concurrent filter fininsh it's job(Chain.doFilter()),when all filter finish their job,servlet will be executed when exist one.
Filter Type
-
REQUEST
It will be called when user visit specific page
the difference between redirect and dispatch should be awared
-
FORWARD
It will be called when requestDispatch.forward()
endless loop should be noticed
-
INCLUDE
It will be called when requestDispatch.include()
-
ERROR
It will be called when error page is visited(error lin)
<!--it couples with servlet to a highly degree-->
-
async
asynchronous handle are supported
Annotation @WebFilter
An Annotation can simplify filter configure work
This annotation is processed by the container at deployment time, and the corresponding filter applied to the specified URL patterns, servlets, and dispatcher types(java ee 6.0).
Name | Type | Description |
---|---|---|
filterName | String | 指定过滤器的 name 属性,等价于 <filter-name> |
value | String[] | 该属性等价于 urlPatterns 属性。但是两者不应该同时使用。 |
urlPatterns | String[] | 指定一组过滤器的 URL 匹配模式。等价于 <url-pattern> 标签。 |
servletNames | String[] | 指定过滤器将应用于哪些 Servlet。取值是 @WebServlet 中的 name 属性的取值,或者是 web.xml 中 <servlet-name> 的取值。 |
dispatcherTypes | DispatcherType | 指定过滤器的转发模式。具体取值包括: ASYNC、ERROR、FORWARD、INCLUDE、REQUEST。 |
initParams | WebInitParam[] | 指定一组过滤器初始化参数,等价于 <init-param> 标签。 |
asyncSupported | boolean | 声明过滤器是否支持异步操作模式,等价于 <async-supported> 标签。 |
description | String | 该过滤器的描述信息,等价于 <description> 标签。 |
displayName | String | 该过滤器的显示名,通常配合工具使用,等价于 <display-name> 标签。 |