web xml
<error-page>
<error-code>403</error-code>
<location>/support/error.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/support/error.jsp</location>
</error-page>
<error-page>
<error-code>405</error-code>
<location>/support/error.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/support/error.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/support/error.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/support/error.jsp</location>
</error-page>
我正在尝试将所有异常和错误映射到一个页面(error.jsp)。如果可以,我可以像这样配置弹簧吗?
答案 0 :(得分:0)
看一下使用SimpleMappingExceptionResolver
。您可以将其SimpleUrlHandlerMapping
视为Exception
。这是一个blogpost,它更多地谈论它。
答案 1 :(得分:0)
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="java.lang.Exception">serviceFault</prop>
</props>
</property>
<property name="defaultErrorView" value="serviceFault" />
</bean>