您的位置:首页 > 移动开发

SimpleMappingExceptionResolver的使用

2016-04-14 11:38 495 查看
[html] view
plain copy







<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">

<!-- 定义默认的异常处理页面 -->

<property name="defaultErrorView" value="error"/>

<!-- 定义异常处理页面用来获取异常信息的变量名,如果不添加exceptionAttribute属性,则默认为exception -->

<property name="exceptionAttribute" value="exception"/>

<!-- 定义需要特殊处理的异常,用类名或完全路径名作为key,异常页面名作为值 -->

<property name="exceptionMappings">

<props>

<prop key="IOException">error/io.jsp</prop>

<prop key="java.sql.SQLException">error/sql.jsp</prop>

</props>

</property>

</bean>

配置这个只能拦截Exception,404错误是拦截不了,要单独在web.xml配置,它比web.xml中配置错误页面强大的地方是可以把异常输出。

web.xml

[html] view
plain copy







<error-page>

<exception-type>java.lang.Exception</exception-type>

<location>/jsp/error.jsp</location>

</error-page>

<error-page>

<error-code>404</error-code>

<location>/jsp/error.jsp</location>

</error-page>

另外发现ajax提交抛异常不受它控制,页面不会跳转。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: