How do I hook up a HandlerExceptionResolver to catch exceptions and errors?
web.xml
开发者_StackOverflow<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?
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>
精彩评论