Spring學習筆記系列(三) 異常處理
配置Spring異常處理之需要增加一個bean的配置:
<!-- Exception Resolver-->
<bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="defaultErrorView">
<value>/exception/failure</value>
</property>
<property name="exceptionMappings">
<props>
<prop key="java.sql.SQLException">/exception/showDBError</prop>
<prop key="java.lang.RuntimeException">/exception/showError</prop>
</props>
</property>
</bean>
這樣就可以統一分別處理不同Exception了。注意jsp頁面在request中attribute等于“exception”,
而不是“Exception”注意大小寫。頁面如下:
<c:set value="${exception}" var="ee"/> |
當然也可以做得更友好些,例如可以顯示隱藏詳細信息。
<!-- Exception Resolver--> <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> <property name="defaultErrorView"> <value>/exception/failure</value> </property> <property name="exceptionMappings"> <props> <prop key="java.sql.SQLException">/exception/showDBError</prop> <prop key="java.lang.RuntimeException">/exception/showError</prop> </props> </property> </bean> |
這樣就可以統一分別處理不同Exception了。注意jsp頁面在request中attribute等于“exception”,
而不是“Exception”注意大小寫。頁面如下:
<c:set value="${exception}" var="ee"/> |
當然也可以做得更友好些,例如可以顯示隱藏詳細信息。
posted on 2007-06-18 18:00 chenguo 閱讀(280) 評論(0) 編輯 收藏 所屬分類: Spring Dev