HandlerExceptionResolver

HandlerExceptionResolver

本文介绍了如何挂接HandlerExceptionResolver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何连接HandlerExceptionResolver来捕获异常和错误?

How do I hook up a HandlerExceptionResolver to catch exceptions and errors?

web.xml

<error-page>
    <error-code>500</error-code>
    <location>/support/500.jsp</location>
  </error-page>

  <error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>/support/500.jsp</location>
  </error-page>

   <error-page>
    <exception-type>java.lang.Throwable</exception-type>
    <location>/support/500.jsp</location>
  </error-page>

500.jsp

//How do I get a stack trace or specific error message in here?


推荐答案

一个简单的例子,

 <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
  <map>
    <entry key="DataAccessException" value="data-error" />
    <entry key="com.stuff.MyAppRuntimeException" value="app-unchecked-error" />
    <entry key="com.stuff.MyAppCheckedException" value="app-checked-error" />
  </map>
</property>
<property name="defaultErrorView" value="general-error"/>
</bean>

这篇关于如何挂接HandlerExceptionResolver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 21:34