过滤器
过滤器的几种格式:
1、过滤所有请求:
1 <filter> 2 <filter-name>ServletAction</filter-name> 3 <filter-class>com.gao.xin.filter.ServletAction</filter-class> 4 </filter> 5 <filter-mapping> 6 <!-- *是这个项目底下所有的请求都经过过滤器 --> 7 <filter-name>ServletAction</filter-name> 8 <url-pattern>/*</url-pattern> 9 </filter-mapping>
2、过滤一个路径下的所有请求:
1 <filter> 2 <filter-name>ServletAction</filter-name> 3 <filter-class>com.gao.xin.filter.ServletAction</filter-class> 4 </filter> 5 <filter-mapping> 6 <!-- 过滤这个路径下的所有请求 --> 7 <filter-name>ServletAction</filter-name> 8 <url-pattern>/login/*</url-pattern> 9 </filter-mapping>
3、过滤一个JSP
1 <filter> 2 <filter-name>ServletAction</filter-name> 3 <filter-class>com.gao.xin.filter.ServletAction</filter-class> 4 </filter> 5 <filter-mapping> 6 <!-- 过滤这个路径下的所有请求 --> 7 <filter-name>ServletAction</filter-name> 8 <url-pattern>/login.jsp</url-pattern> 9 </filter-mapping>