过滤器配置
- xml文件配置
<filter>
<filter-name>helloFilter</filter-name>
<filter-class>com.hwua.filter.HelloFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>helloFilter</filter-name>
<url-pattern>/alter.jsp</url-pattern>
<!--过滤请求过来的页面-->
<dispatcher>REQUEST</dispatcher>
<!--过滤转发过来的页面-->
<dispatcher>FORWARD</dispatcher>
<!--过滤动态导入的页面-->
<dispatcher>INCLUDE</dispatcher>
<!--过滤因发生错误跳转过来的页面-->
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<error-page>
<!--当应用中的某一个页面出现错误时,会直接跳转到index.jsp-->
<exception-type>java.lang.ArithmeticException</exception-type>
<location>/alter.jsp</location>
</error-page>
- 注解配置
/**
*urlPatterns 要过滤的资源的名称
*dispatcherTypes 要过滤的加载资源的方式 默认情况下请求request资源 才过滤
* DispatcherType.ERROR //错误页面跳转
* DispatcherType.FORWARD //转发
* DispatcherType.INCLUDE //动态加载页面
* DispatcherType.REQUEST //请求
@WebFilter(urlPatterns = "/*" ,dispatcherTypes = {DispatcherType.ERROR,DispatcherType.FORWARD,DispatcherType.INCLUDE,DispatcherType.REQUEST})