web.xml注册filter:
<filter>
<filter-name>helloFilter</filter-name>
<filter-class>cn.buaa.javaweb.HelloFilter</filter-class>
<init-param>
<param-name>name</param-name>
<param-value>value</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>helloFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
filter的顺序是按照在web.xml里注册的顺序来执行的。
补充:FilterChain
假设有FilterChain里有两个filter,分别为filter1和filter2,如果在filter1的dofilter里调用了chain.dofilter(),那么顺序是:filter1的init -> filter1的dofilter -> filter2的init -> filter2的dofilter -> filter2的destroy -> filter1的destroy。
<filter>
<filter-name>helloFilter</filter-name>
<filter-class>cn.buaa.javaweb.HelloFilter</filter-class>
<init-param>
<param-name>name</param-name>
<param-value>value</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>helloFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
filter的顺序是按照在web.xml里注册的顺序来执行的。
补充:FilterChain
假设有FilterChain里有两个filter,分别为filter1和filter2,如果在filter1的dofilter里调用了chain.dofilter(),那么顺序是:filter1的init -> filter1的dofilter -> filter2的init -> filter2的dofilter -> filter2的destroy -> filter1的destroy。