如何连接HandlerExceptionResolver

时间:2011-09-13 16:38:35

标签: spring exception-handling

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

的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?

1 个答案:

答案 0 :(得分:1)

未经检查和已检查异常的简单示例将是

 <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>