一:声明式异常处理机制:
通过在web.xml文件中设置errorPage标签,声明发生错误时,指定跳转页面。
一种形式为:
<error-page>
<error-code>404</error-code>
<location>/404.jsp</location>
</error-page>
但是在这里没有成功跳转到指定页面,以下是一些解释:
1, error-page实际上是一种业务手段,让异常被转到特定页面。
既然是业务手段,则要求该异常需要从业务代码中抛出(也就是我们自己开发的代码),
容器只是帮我们转到目标页面而已。
而java.lang.IllegalStateException,我们看看这个类的说明:
Signals that a method has been invoked at an illegal or inappropriate time. In other words, the Java environment or Java application is not in an appropriate state for the requested operation.
这个异常是由jvm或者是由容器抛出的异常(容器判断我们的应用处在不合适的状态,比如:session已经失效,或者已经向客户端返回数据却要求forward等),
所以当容器认为自身的某些规则都被违背的时候,不应该转向处理业务异常的页面,而是要转向容器自己的出错页面。
二:在web.xml文件中部署多个过滤器,类似于下面的代码:
<filter>
<filter-name>TestFilter01</filter-name>
<filter-class>cn.imust.filter.TestFilter01</filter-class>
</filter>
<filter>
<filter-name>TestFilter02</filter-name>
<filter-class>cn.imust.filter.TestFilter02</filter-class>
</filter>
//当访问一个资源时,过滤器按照<filter-mapping>标签顺序执行拦截操作。
<filter-mapping>
<filter-name>TestFilter02</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>TestFilter01</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
通过在web.xml文件中设置errorPage标签,声明发生错误时,指定跳转页面。
一种形式为:
<error-page>
<error-code>404</error-code>
<location>/404.jsp</location>
</error-page>
但是在这里没有成功跳转到指定页面,以下是一些解释:
1, error-page实际上是一种业务手段,让异常被转到特定页面。
既然是业务手段,则要求该异常需要从业务代码中抛出(也就是我们自己开发的代码),
容器只是帮我们转到目标页面而已。
而java.lang.IllegalStateException,我们看看这个类的说明:
Signals that a method has been invoked at an illegal or inappropriate time. In other words, the Java environment or Java application is not in an appropriate state for the requested operation.
这个异常是由jvm或者是由容器抛出的异常(容器判断我们的应用处在不合适的状态,比如:session已经失效,或者已经向客户端返回数据却要求forward等),
所以当容器认为自身的某些规则都被违背的时候,不应该转向处理业务异常的页面,而是要转向容器自己的出错页面。
二:在web.xml文件中部署多个过滤器,类似于下面的代码:
<filter>
<filter-name>TestFilter01</filter-name>
<filter-class>cn.imust.filter.TestFilter01</filter-class>
</filter>
<filter>
<filter-name>TestFilter02</filter-name>
<filter-class>cn.imust.filter.TestFilter02</filter-class>
</filter>
//当访问一个资源时,过滤器按照<filter-mapping>标签顺序执行拦截操作。
<filter-mapping>
<filter-name>TestFilter02</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>TestFilter01</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>