问题
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?
回答1:
a simple example for both unchecked and checked exception would be
<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>
来源:https://stackoverflow.com/questions/7405380/how-do-i-hook-up-a-handlerexceptionresolver