ProjectDescription
Filter的使用
- 创建类实现javax.servlet.Filter.
- 重写方法:
- init(); //过滤器初始化
- doFilter(); //过滤请求
1.chain.doFilter(request, response); //向下转发请求 - destroy(); //销毁过滤器
- 在web.xml中注册
<filter> <filter-name>filter</filter-name> <filter-class>com.filter.FilterTest</filter-class> </filter> <filter-mapping> <filter-name>filter</filter-name> <url-pattern>/filter/*</url-pattern> </filter-mapping>