1. 程式人生 > >整理: JAVA錯誤處理集錦

整理: JAVA錯誤處理集錦


0、 需要識別符號
a) 不在函式內
1、 非法表示式開始
b) 可能:丟失括號 .
2. no data found
a) 可能:setInt(1,100)中,沒有100這個值
3. 找不到符號
a) 可能:沒匯入包
4. 指定了無效URL
a) 可能:資料庫名或IP錯誤,即連接出錯
5. 類路徑沒有找到
a) 可能: ClassNotFoundException: oracle.jdbc.driver.OracleDriver
b) 原因: 一般是指包名寫錯,或者沒有import包,或者沒有在類路徑中找到jar檔案
c) 解決: 沒有載入Oracle驅動jar,在.bash_profile中把ojdbc14.jar加進來
6. 空指標異常
a) 可能: 資料來源錯誤 比如資料庫名或IP錯誤
7. 不能執行查詢
a) 可能: 資料庫中表的問題,比如列名不存在
8. invalid identity
a) 可能: 列名出錯
9. 若在資料庫中建立了 兩個sequence ,執行時出現異常可能是先後執行了多次select語句,導致與原有的序列號產生衝突
10. 表名或列名不存在
a) 可能:表不存在或者沒有插入資料到表中
11. 不支援的類,類的版本錯誤
a) 可能:沒有匯入jdk5.0,或者編譯器仍為1.4
12. MappingNotFoundException
a) Maybe: In the Eclipse Not refersh , or not exist in the dirctory
13. HibernateException: /hibernate.cfg.xml not found
a) Maybe1: hibernate.cfg.xml not in the root directory
b) Maybe2: Could not parse configuration .
c) resolve: database not connect or use another database
14. ConstraintViolationException
a) Maybe: used a not true database
15. 驅動沒有找到 或者 JDBC Driver not found
可能:連線資料庫的驅動jar包不存在或者版本不一致,比如將舊的版本換成新的會造成該類錯誤
16. 空指標異常 , java.lang.NullPointerException
a) 可能1:資料庫連接出錯,比如在hibernate.cfg.xml中的資料錯誤會導致異常。
17. 資料插入異常 ,GenericJDBCException: could not insert
a) 可能1:沒有建立表或者表中沒有任何資料
b) 可能2:插入資料後沒有執行提交語句:commit
18. LazyInitializationException 或者延遲載入異常
a) 可能1:沒有在查詢語句中加fetch
19. IdentifierGenerationException
a) 可能1:高位表沒有初始化(比如hi_value中沒有記錄)
20. could not initialize a collection: [hibernate.entity.Role.modules#32768] Syntax error: Encountered "-" at line 1, column 132.
a) 錯誤原因:<set name="modules" table="module-role" lazy="false">紅色字部分中“-”為非法字元,替換為module_role
21. could not insert collection rows: [hibernate.entity.Module.roles#1]
 在Module.hbm.xml檔案的如下配置中加入inverse=”true”
<set name="roles" table="module_role" inverse="true">

22.在部署Struts時,出現如下錯誤資訊:
HTTP Status 404 - Servlet action is not available
 
type Status report
message Servlet action is not available
description The requested resource (Servlet action is not available) is not available.
問題原因:
1.、web.xml檔案中未配置ActionServlet。
2、struts-config.xml檔案未配置你要訪問的Action。
3、你的jsp檔案form標記中action屬性的路徑名稱錯誤。
4、非以上三種情況。
針對以上4種情況相應的解決方案如下:
1、在web.xml檔案中加上ActionServlet的配置資訊
?????? /WEB-INF/struts-config.xml?
?2、在struts-config.xml檔案檢查你要訪問的Action配置檔案。
3、檢查jsp檔案form標記中action屬性的路徑名稱是否與struts-config.xml檔案中action標記的path屬性的路徑名稱一致。
4、非以上情況的解決辦法就是檢查web容器的log日誌,如果時tomcat則檢查下logs目錄下的localhost_log檔案,看裡邊是否記錄有錯誤資訊,然後根據錯誤資訊提示將其糾正。

23.java.lang.NoClassDefFoundError: org/apache/commons/beanutils/Converter
缺少spring-framework-2.0.3\lib\jakarta-commons\commons-beanutils.jar
24.
ava 程式碼Caused by: java.lang.NoClassDefFoundError: org/objectweb/asm/Type  
缺少spring-framework-2.0.3\lib\asm\asm-2.2.2.jar包,版本不同,該包的名字有相應的區別

java 程式碼Caused by: java.lang.NoClassDefFoundError: org/dom4j/DocumentException  
缺少spring-framework-2.0.3\lib\dom4j\dom4j-1.6.1.jar包,版本不同,該包的名字有相應的區別
把這個包進去就可以了:\Spring206\lib\dom4j、dom4j-1.6.1.jar

java 程式碼Caused by: java.lang.NoClassDefFoundError: org/apache/commons/collections/SequencedHashMap  
缺少spring-framework-2.0.3\lib\jakarta-commons\commons-collections.jar包,版本不同,該包的名字有相應的區別

java 程式碼Caused by: java.lang.NoClassDefFoundError: net/sf/cglib/proxy/CallbackFilter  
缺少spring-framework-2.0.3\lib\cglib\cglib-nodep-2.1_3.jar包,版本不同,該包的名字有相應的區別

java 程式碼Caused by: java.lang.NoClassDefFoundError: org/objectweb/asm/CodeVisitor  
缺少hibernate-3.2\lib\asm.jar包,版本不同,該包的名字有相應的區別

java 程式碼
org.hibernate.exception.SQLGrammarException: could not load an entity: [www.proudsoul.xml.User#1]
JAVA工程與WEB工程包的區別:一個是asm.jar,一個是jta.jar

java 程式碼Caused by: java.lang.NoClassDefFoundError: javax/transaction/TransactionManager  
缺少spring-framework-2.0.3\lib\j2ee\jta.jar包,版本不同,該包的名字有相應的區別此種錯誤請檢查相應的***.hbm.xml配置檔案的配置

25,
Exception in thread "main" org.springframework.dao.InvalidDataAccessResourceUsageException: could not get next sequence value; nested exception is org.hibernate.exception.SQLGrammarException: could not get next sequence value
Caused by: org.hibernate.exception.SQLGrammarException: could not get next sequence value
原因:沒有加Sequence或者資料庫的方言寫錯了

26,
我的配置檔案
    <id name="id" column="id">
            <generator class="native" />
        </id>
然後我執行儲存一條資料進去
The database returned no natively generated identity value
就會報這個錯誤
因為你native是根據看底層資料庫的能力選擇identity, sequence 或者hilo中的一個
而我建表的時候id沒有指定
alter table `student` change `id` `id` int auto_increment
我們把我們的表的結構小小的改動一下就沒問題了

27,
UpdateManager無法啟動2007-08-09 15:21如果在應用程式安裝過程中,暴力中斷安裝程式,會出現如下狀況:1.apt-get remove 和dpkg --remove 無法刪除軟體 2.UpdateManager無法啟動3.新立得軟體包管理程式無法啟動
以上可能是deb損壞之類造成的
sudo dpkg -r sqldveloper
正在讀取軟體包列表... 完成
正在分析軟體包的依賴關係樹... 完成
E: 軟體包 sqldeveloper 需要重新安裝,但是我無法找到相應的安裝檔案。
解決方法:1.從 /var/lib/dpkg/status 中把對應的段刪掉
重要:修改之前請先備份
在status中找到你對應的包刪除就OK了...

28,
Exception in thread "main" java.lang.NoClassDefFoundError: antlr/ANTLRException
少了antlr-2.7.5H3.jar包,從D:\eclipse\eclipse\plugins\com.genuitec.org.hibernate.eclipse_4.1.1\myeclipse-data\3.0\lib

29,
Caused by:
java.lang.NoClassDefFoundError: javax/transaction/Synchronization
缺少Spring206\lib\j2ee\jta.jar

30,
Caused by:
java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy3] to required type [business.impl.PriceBiz] for property 'priceBiz': no matching editors or conversion strategy found
在java類中設定priceBiz時應該設定的是介面PriceBizIf,而非實現類

18, 陣列越界
 可能1: 在命令列後面需要加入引數.
 可能2:加入的引數錯誤
19, car is not mapped
 可能1: 在cfg.xml中沒有增加對映的hbm.xml檔案在<mapping.../>中   
20, 屬性沒有找到
 可能1: hbm.xml檔案中的 <property name =""> 有問題, 也許是name的值與對應類中的成員名不一致
21,SQLException: 無當前連線          可能1:在比如建立帳戶時沒有對相應的方法新增到<list>中去,比如這個沒有加入:<value>newAccount</value>
 
 <bean id="transactionAdvisor" class="org.springframework.aop.support.NameMatchMethodPointcutAdvisor">
  <property name="advice">
   <ref bean="advice"/>
  </property>
  <property name="mappedNames">
   <list>
    <value>transfer</value>
   </list>
 </bean>
22,SQLException: Syntax error: Encountered "table" at line 1, column 8.
 可能1;執行SQL時出現衝突,可能是SQL語句中使用了關鍵字作為變數來用,比如
  update order set balance=1000000;
  其中order被用作表名來使用,這是錯誤的,因為order是個關鍵字,用在order by中

23, Servlet /Spring-WebMvc threw load() exception
org.xml.sax.SAXParseException: Document root element "beans", must match DOCTYPE root "null".
 jar包的衝突,spring-1.2.6.jar和spring.jar出現在一個war的目錄中:JBoss/server/all/deploy/Spring-WebMvc.war/WEB-INF/lib   

24, java.sql.SQLException: 當事務仍處於活動狀態時,無法關閉連線。


25 ,
validateJarFile(/home/soft01/Tomcat/webapps/sms-token-struts/WEB-INF/lib/servlet-api.jar)
Servlet /sms-struts-tiles threw load() exception
java.lang.ClassNotFoundException: org.apache.struts.action.ActionServlet
原因:在WEB-INF/lib/ 目錄下有servlet-api.jar與/Tomcat/common/lib目錄下的servlet-api.jar衝突了,把WEB-INF/lib/下的servlet-api.jar刪除就可以了

26,java.lang.ClassNotFoundException: org.springframework.web.struts.ContextLoaderPlugIn
Marking servlet action as unavailable
10:30:47,088 ERROR [/NetCT_OSS]:3953 - Servlet /NetCT_OSS threw load() exception
javax.servlet.UnavailableException

27,org.xml.sax.SAXParseException: Document root element "beans", must match DOCTYPE root "null".
缺少MyEclipse/eclipse/plugins/com.genuitec.eclipse.springframework_5.5.0/data/2.0/dist/modules/spring-struts.jar

28,Caused by: java.sql.BatchUpdateException: ORA-02291: integrity constraint (SD0702.FK82D343CF49A4B831) violated - parent key not found
Caused by: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
有可能是ID生成策略的問題,我將它XML對映檔案改成<generator class="increment" />就好了

29,
2007-08-19 16:21:43,290 ERROR [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/OSS].[action]] - Servlet.service() for servlet action threw exception
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [entity.Module#2]
java.util.ConcurrentModificationException
原因:已經有物件擁有了所選擇的module,用clear(),而不是remove();

30,
ERROR [org.apache.catalina.session.ManagerBase] - IOException while loading persisted sessions: java.io.InvalidClassException: entity.Module; local class incompatible: stream classdesc serialVersionUID = -5988350031935445758, local class serialVersionUID = -297934247726484429
java.io.InvalidClassException: entity.Module; local class incompatible: stream classdesc serialVersionUID = -5988350031935445758, local class serialVersionUID = -297934247726484429
在Module中加上一個關鍵字:transient

31,
Caused by: java.sql.BatchUpdateException: ORA-02292: integrity constraint (SD0702.SYS_C00132664) violated - child record found
原因:有其他的表引用了該表的外建,所以報這個異常,如果沒有引用就不會出現

32,
出現數組越界的時候,看看是不是迴圈時沒有加=,比如:
for(int i = 1; i<arr.length;i++)可以改成
for(int i = 1; i<=arr.length;i++)

 

1.如果使用Ant和Junit是被報找不到test,檢查一下是否誤用了private
出錯資訊:
    <failure message="No tests found in test.AllTest" type="junit.framework.AssertionFailedError">junit.framework.AssertionFailedError: No tests found in test.AllTest
該錯誤有個很特別的特點,當你不通過ant來執行測試,而是通過AllTest類來執行的話,可以正常執行。小心哦

2.如果遇到報:表名無效,且jvm報嚴重錯誤,看看是不是用了資料庫的保留關鍵字來做表名了,如User。

3.使用ant時必須小心ant的classpath它用的不是IDE的classpath,小心!

4.小心下邊的異常,
exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of xp.bean.Users.?" type="net.sf.hibernate.PropertyAccessException">java.lang.ClassCastException at xp.bean.UsersMetaClass1.setPropertyValues(<generated>) at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues
上次出現該錯錯誤的原因是:
原始檔裡我的class型別為一個類Contact contact
而跑到mapping裡卻成了Set,呵呵厲害。

5.突然間冒出大量的NullPointException
重新build一下看看先。

6.="Flush during cascade is dangerous - this might occur if an object was deleted and then re-saved by cascade"

7.Tapestry的出錯資訊:
Class com.bookshop.Hello does not implement the IPage interface.
location: context:/WEB-INF/Home.page, line 6
原因:與顯示有關的哪個java類沒有從IPage家族繼承。

8.使用ant時給出的路徑好象不允許出現空格。

9.由於使用ant時用junit做測試的話,classpath中出現j2ee.jar的話,問題多多。例如xml格式的log檔案生成不了,莫名其妙的NullPointException等。所以我設定了兩個包個包含j2ee.jar,為編譯用;一個沒有,為junit用

10.進行單元測試時,在查詢返回後應馬上assertNotNull(),這樣可以更快速的定位NullPointException

11.要使用ResourceBundle的話,要千萬小心。必須用日誌記錄下它的狀態。還有該屬性檔案應該放在classes下面。

12.當要顯示任何頁面時,都被提示無效,那麼應該檢查一下lib目錄了,還有一些很奇怪的異常,例如你明明可以找到一個類但是伺服器卻提示ClassNotDefException,那麼估計是缺少了該類所必須的包了。或者多了不相容的包,如, xdoclet系列包不被struts的lib目錄所相容

13.編寫clone時從Java程式設計思想(2nd)上學到的(732):
.引數傳遞過程中會自動產生別名(alias)。
.沒有局域物件(local objects),只有局域性的(local)references。
.reference受範圍(scope)的限制,物件則否。
.物件的壽命從來不是Java的討論議題(因為有垃圾回收機制)

14.try catch finally的域居然是分離的。

15.jsp亂碼的其中一個原因:charset="gb2312" 等號"="的兩邊不允許有空格。

16.我的基於Displaytag的簡單報表解決方案。
http://displaytag.sourceforge.net/
下載displaytag.jar和displaytag.tld
displaytag.jar放在lib目錄,而displaytag.tld放在WEB-INF目錄,在web.xml中為displaytag.tld宣告一下。
  <taglib>
    <taglib-uri>http://displaytag.org</taglib-uri>
    <taglib-location>/WEB-INF/displaytag.tld</taglib-location>
  </taglib>
在jsp裡使用前,加上
  <%@ taglib uri="http://displaytag.org" prefix="display" %>
       
注意該軟體有個bug,他要用的一個包common-lang.jar版本必須在2.0以上。
如果碰到下面異常,則應堅持一下是否該包的版本問題。
java.lang.NoSuchMethodError: org.apache.commons.lang.StringUtils.capitalize(Ljava/lang/String;)Ljava/lang/String;
然後就可放心使用了
<display:column property = "xxx"/>其中xxx為物件中的帶有getter的變數>。
定義表格的樣子,用css定義。如
TABLE.its THEAD TR {
 BACKGROUND-COLOR: #69c
}
TABLE.its TR.even {
 BACKGROUND-COLOR: #def
}
在使用分頁時,可能會出現這種情況,點選其他頁時,彈出下載視窗,讓你下載當前jsp頁面,這是因為你在當前頁面讀取了資料的緣故。解決辦法為在action裡讀取資料而不是在jsp裡。可以參考
http://www.displaytag.org/example-paging.jsp?d-26189-p=2

17.使用displaytag時,在一列中放入多個元素
必須在display:table中定義一個id
<display:table name = "allBooks" class = "its" pagesize = "5" id = "item">
  <display:column title = "操作">
    <a href = "/Bookshop/admin/bookManagement.do?action=view&id=<%=((Book)item).getId()%>" target = "_blank" >檢視</a>
    <a href = "/Bookshop/admin/bookManagement.do?action=edit&id=<%=((Book)item).getId()%>">編輯</a>
    <a href = "/Bookshop/admin/bookManagement.do?action=delete&id=<%=((Book)item).getId()%>">刪除</a>
  </display:column>
要在displaytag中使用連結,必須具備paramId,否則不顯示為連結
 <display:column property = "product.name" href = "viewDetailV2.0.jsp" title = "書名" paramId="item" paramProperty="product.id"/>
可以這樣使用display
  <display:column property = "product.id" title = "ID"/>
其中product為物件

18.<bean:write name = "xxxx" property = "xxx"/> 可以直接取到session.getAttribute()取到的東西。

19.實驗struts-upload例子時要注意的地方:
   1.If you would rather write this file to another file, please check here:
 這一行要打鉤
   2.If you checked the box to write to a file, please specify the file path here:
在這裡要重新命名如:c:\b.jpg
上傳成功的話,會出現提示 The file has been written to "c:\b.jpg"

20.Hibernate的like可以這麼用:
      Query query = session.createQuery("from src.persistent.Book as book where upper(book.name) like :name ");
      query.setString("name", "%");
      result = query.list();

21.Hibernate出現 duplicate import : className
異常也可能是因為忘了為持久類在configuration中addClass了
     
22.<logic:iterate id = "author" name = "authors">
name所引用的是session裡的attribute。

23.如果發現要出現詢問下載的情況,有可能是因為要跳轉的頁面出現了問題。試試在要跳轉到的頁刪掉
<%@ page contentType="text/html; charset=gb2312"%>

24.如果JSP頁面跳轉時出現下邊的錯誤資訊:
The request sent by the client was syntactically incorrect (Invalid path /web/shoppingCart was requested).
原因是struts-config的action = "x" 寫成了 action = "x.do"

25.在struts中,strut-config.xml中,forward時使用redirect = "true"可以將.do重定向為.jsp

26.以後在判斷相等性之前先用logger把兩個值顯示出來。

27.從session裡getAttribute後,修改並不需要重新setAttribute一次。

28.在hibernate中使用subclass是一棵繼承樹共用一個表,僅生成個mapping。
每個類中必須有discrimator-value。在最上層的類中必須宣告:
@hibernate.discriminator column = "class"。
不可以將子類新增到configuration裡去。(即不可addClass(子類))
使用Xdoclet的建立subclass的例子(該類是父類)
/**
 * @hibernate.class discriminator-value = "customer"
 * @hibernate.discriminator column = "class"
 */

而使用joined-subclass則是一類一表,也不許將子類新增進configuration裡去。
/**
 * @hibernate.joined-subclass
 * @hibernate.joined-subclass-key
 * column="customer_id"
 */
如果發現生成的mapping檔案中joined-subclass的key column為空,那麼可能是@hibernate.joined-subclass-key這句沒有寫對。
用joined-subclass生成的表,仔細看。Member extends Customer
create table Customer (
   id VARCHAR2(255) not null,
   name VARCHAR2(255),
   description VARCHAR2(255),
   primary key (id)
)
create table Member (
   customer_id VARCHAR2(255) not null,
   password VARCHAR2(255),
   primary key (customer_id)
)

29.在junit中儘量使用assertEquals代替assertTrue;

30.Hibernate
如果Child extends Parent
那麼from Parent as parent 也將會將Child選出來,而from Child as child 則不會選出Parent

31.Hibernate
使用hibernate的one-to-one時,應該兩方向都set,否則會報save NullPointException
parent.setChild(child);
child.setParent(parent);

32.Hibernate
遇到下邊的異常,估計是與因為外來鍵出現了問題:

java.lang.NullPointerException
 at net.sf.hibernate.persister.AbstractEntityPersister.getPropertyValue(AbstractEntityPersister.java:675)
 at net.sf.hibernate.id.ForeignGenerator.generate(ForeignGenerator.java:33)
如:
* @hibernate.id generator-class = "foreign"
* @hibernate.generator-param name = "property" value = "customer"
* @hibernate.one-to-one name = "custmoer" class = "src.persistent.Customer"
value的值和one-to-one 中name的值不符,則會出現上邊的異常。如果不顯示指定name則預設取成員變數名

Customer a
則name = "a" 需要小心的是不是類名。所以,以後最好顯示指定名字為好。

33.出現異常:
Exceptionobject references an unsaved transient instance - save the transient instance before flushing: src.persistent.Product
原因沒有為某物件進行set設定, 如上邊的這個就是某物件沒有呼叫setProduct

34.
"xxx action = "/a" 不用.do和根目錄名
<a href = "b.do" 需要.do和根目錄名

35.
Caused by: java.sql.SQLException: ORA-02291: 違反完整約束條件 (BOOKSHOP.FK4AAEE
47687CCA6B) - 未找到父項關鍵字
如果你覺得該做的e是出現這個問題,那麼檢查一下,是否將類的繼承關係在hibernate的mapping中反映了出來。joined-subclass或subclass
例如a extends b
如果持久類c 需要Set的是持久類a,那麼你把b傳入,而b又沒有在mapping中將父子關係反映出來的話,就會出現該異常

36.使用DynaActionForm需要注意的問題
在struts-config宣告
<form-bean name="memberloginForm" dynamic ="true" type="org.apache.struts.action.DynaActionForm">
  <form-property name = "name" type = "java.lang.String"/>
  <form-property name = "password" type = "java.lang.String"/>
</form-bean>
在Action裡將form強制轉化成DynaActionForm,然後get("屬性名")就可以了

37.那位大俠能給出一個用hibernate進行分頁得實際例子,學習中!
http://forum.hibernate.org.cn/viewtopic.php?t=1772
Query q = s.find(".....");
q.setFirstResult(10);   //  從第11條記錄開始
q.setMaxResults(100);  //  取出100條
......

38.struts的validate最簡單實現
1.首先準備好錯誤提示資訊。
xxx.properties 裡
errors.required={0} is required.(預設已有)
2.Form必須從ValidatorForm繼承
3.不可以過載ValidatorForm的validate函式
4.在validate.xml中為你想驗證的表單進行驗證設計。例如
<form name="logonForm">
    <field property="userName" depends="required">
 <arg0 key="prompt.userName"/>
 (該引數將在顯示錯誤資訊是從xxx.properties讀取prompt.userName,填入{}方括號裡,取代0。如果是arg1將將填入{1}位置,以此類推。
    </field>
</form>
不需要在action裡做任何處理。只管forward就行了。作為forward的目標頁,不需要任何有關用於處理出錯資訊的處理。

39.伺服器報
The requested resource (/xxxx/xxx.htm) is not available.的很奇怪的一個的可能原因
在web.xml中定義的tld,沒有找到
或者是lib目錄下的包太多出現了問題。

  <taglib>
    <taglib-uri>/spring</taglib-uri>
    <taglib-location>/WEB-INF/spring.tld</taglib-location>
  </taglib>
如WEB-INF目錄下不存在spring.tld的話,就會報上邊的錯誤

40.
spring的xxx-servlet.xml的使用SimpleFormController系列的類問題:
  <bean id = "priceIncreaseForm" class="PriceIncreaseFormController">
    <property name="sessionForm"><value>true</value></property>
    <property name="beanName"><value>priceIncrease</value></property>
    <property name="commandClass"><value>PriceIncrease</value></property>
    <property name="formView"><value>priceIncrease</value></property>
    <property name="successView"><value>hello</value></property>
    <property name="productManager">
      <ref bean="prodMan"/>
    </property>
  </bean>
這裡要注意幾個問題:
(1)上邊的PriceIncrease是了類名,必須在classes裡存在該類,否則報:
PropertyVetoExceptionsException: 1 errors:-- ErrorCodedPropertyVetoException: message=[Failed to convert property value of type [java.lang.String] to required type [java.lang.Class] for property named 'commandClass'; nested exception is:
 java.lang.IllegalArgumentException: Invalid class name [PriceIncrease]: PriceIncrease]; errorCode=[typeMismatch]
java.lang.IllegalArgumentException: Invalid class name [PriceIncrease]: PriceIncrease
(2)<property name="formView"><value>priceIncrease</value></property>
這一行必不可少,priceIncrease是頁面的名字,他將會是prefix + priceIncrease + suffix
如果缺少該行,則報:
javax.servlet.ServletException: Error in ModelAndView object or View resolution encountered by servlet with name 'pocketSpring': View to render cannot be null with ModelAndView [ModelAndView: materialized View is [null]; Model=[{

[email protected], org.springframework.validation.BindException.priceIncrease=org.springframework.validation.BindException: BindException: 0 errors}]]

使用Errors的rejectValue相關問題:
rejectValue(java.lang.String field, java.lang.String errorCode, java.lang.Object[] errorArgs, java.lang.String defaultMessage)
Reject the given field of the current object, using the given error description.
當前物件指的是xxx-servlet.xml中與validator類有聯絡的哪個物件。
         
第一個是:當前物件的屬性名,必須存在
第二個是:將要從屬性檔案中讀取的訊息
第三個是:傳遞給所讀取的訊息的引數,如:
error.too-low=You have to specify a percentage higher than {0}!
第四個是:當從屬性檔案中讀取訊息不成功時,所reject的值

以後從request中讀取parameter可以借用spring的RequestUtils包裡的
getStringParameter
public static java.lang.String getStringParameter(javax.servlet.http.HttpServletRequest request,
                                           &bsp;      java.lang.String name,
                                                  java.lang.String defaultVal)
Get a string parameter, with a fallback value. Never throws an exception. Can pass a distinguished value to default to enable checks of whether it was supplied.
不會拋異常
Hibernate的問題:2.1rc的問題
INFO: cache provider: net.sf.ehcache.hibernate.Provider
net.sf.hibernate.HibernateException: could not instantiate CacheProvider:
解決辦法,2.1rc比以前的版本多需要一個包
ehcache.jar

43.static的問題
static函式只可以訪問static成員變數。
而static變數可以被任何成員函式訪問。

44.
java.lang.NoClassDefFoundError: javax/transaction/Synchronization];
需要新增JTA.jar