日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

解讀Spring異常處理_JSP教程

編輯Tag賺U幣
教程Tag:暫無Tag,歡迎添加,賺取U幣!

推薦:Spring學(xué)習(xí)基礎(chǔ)---配置文件
1,配置文件的配置頭 ?xmlversion=1.0encoding=UTF-8? !-- -ApplicationcontextdefinitionforJPetStore’sbusinesslayer. -ContainsbeanreferencestothetransactionmanagerandtotheDAOsin -dataAccessContext-local/jta.xml(seeweb.xml’scontextConfigLo

配置Spring異常處理之需要增加一個(gè)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>

這樣就可以統(tǒng)一分別處理不同Exception了。注意jsp頁面在request中attribute等于“exception”,
而不是“Exception”注意大小寫。頁面如下:
錯(cuò)誤顯示頁面

  <c:set value="${exception}" var="ee"/>
  <jsp:useBean id="ee" type="java.lang.Exception" />
  <%=ee.getMessage()%><br>
<%ee.printStackTrace( new java.io.PrintWriter(out));%> 
 

當(dāng)然也可以做得更友好些,例如可以顯示隱藏詳細(xì)信息。

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<%@ taglib prefix="spring"  uri="http://www.springframework.org/tags"%>
<%@ page contentType="text/html;charset=GBK" language="java" pageEncoding="GBK"%>
<%@ page import="java.util.Enumeration,java.util.Iterator"%>
<script>
 function showErr(){
  var isHidde = document.all.isHidde.value;
  //alert(isHidde);
  if( isHidde == "true" ){
   document.all.errdiv.style.display=’block’;
   document.all.isHidde.value= ’false’;
   document.all.showbtn.value="隱藏錯(cuò)誤信息";
  }else{
   document.all.errdiv.style.display=’none’;
   document.all.isHidde.value= ’true’;
   document.all.showbtn.value="顯示錯(cuò)誤信息";
  }
 }
</script>
<html>
 <head>
  <title>this is failure</title>
 </head>
 <body onload="showErr()"> 

<c:set value="${exception}" var="ee"/>
  <jsp:useBean id="ee" type="java.lang.Exception" />
  <%=ee.getMessage()%>ok,<br>
  
  
  <table id="errdiv" align="center" bgcolor="darkseagreen">
  <tr><td>
  <font color=red>
  <%ee.printStackTrace( new java.io.PrintWriter(out));%>
  </font>
  </td></tr></table>
  <input type="hidden" id="isHidde" value="true"/>
  <input type="button" id="showbtn" onclick="showErr();"/>

 </body>
</html>

 

分享:Spring學(xué)習(xí)基礎(chǔ)---多框架集成
ApplicationContextctx 1,定義資源文件獲得資源文件的消息,國際化信息 beanid=messageResourceclass=org.springFramework.context.support.ResourceBoundleMessageSource propertyname=basenames xxxx /property /bean 將會搜索xxxx.properties,xxxx_

來源:模板無憂//所屬分類:JSP教程/更新時(shí)間:2010-02-26
相關(guān)JSP教程