異常
org.apache.jasper.JasperException: Cannot retrieve definition for form bean null
可能原因
這個異常是因為Struts根據(jù)struts-config.xml中的mapping沒有找 到action期望的form bean客冈。大部分的情況可能是因為在form-bean中設(shè)置的name屬性和action中設(shè)置的name屬性不匹配所致。換句話說恩尾,action和 form都應(yīng)該各自有一個name屬性助赞,并且要精確匹配橡卤,包括大小寫菩收。這個錯誤當(dāng)沒有name屬性和action關(guān)聯(lián)時也會發(fā)生诡壁,如果沒有在action 中指定name屬性触机,那么就沒有name屬性和action相關(guān)聯(lián)颠区。當(dāng)然當(dāng)action制作某些控制時削锰,譬如根據(jù)參數(shù)值跳轉(zhuǎn)到相應(yīng)的jsp頁面,而不是處 理表單數(shù)據(jù)毕莱,這是就不用name屬性喂窟,這也是action的使用方法之一。
異常
No action instance for path /xxxx could be created
可能原因
特別提示:因為有很多中情況會導(dǎo)致這個錯誤的發(fā)生央串,所以推薦大家調(diào)高你的web服務(wù)器的日志/調(diào)試級別磨澡,這樣可以從更多的信息中看 到潛在的、在試圖創(chuàng)建action類時發(fā)生的錯誤质和,這個action類你已經(jīng)在struts-config.xml中設(shè)置了關(guān)聯(lián)(即添加 了<action>標(biāo)簽)稳摄。
在struts-config.xml中通過action標(biāo)簽的class屬性指定的action類不能被找到有很多種原因,例如:定位編譯后 的.class文件失敗饲宿。Failure to place compiled .class file for the action in the classpath (在web開發(fā)中厦酬,class的的位置在r WEB-INF/classes胆描,所以你的action class必須要在這個目錄下。例如你的action類位于WEB-INF/classes/action/Login.class,那么在 struts-config.xml中設(shè)置action的屬性type時就是action.Login).
拼寫錯誤仗阅,這個也時有發(fā)生昌讲,并且不易找到,特別注意第一個字母的大小寫和包的名稱减噪。
異常
javax.servlet.jsp.JspException: No getter method for property username of bean org.apache.struts.taglib.html.BEAN
可能原因
沒有位form bean中的某個變量定義getter 方法
這個錯誤主要發(fā)生在表單提交的FormBean中短绸,用struts標(biāo)記<html:text property=”username”>時,在FormBean中必須有一個getUsername()方法筹裕。注意字母“U”醋闭。
異常
java.lang.NoClassDefFoundError: org/apache/struts/action/ActionForm
可能原因
這個錯誤主要發(fā)生在在classpath中找不到相應(yīng)的Java .class文件。如果這個錯誤發(fā)生在web應(yīng)用程序的運(yùn)行時朝卒,主要是因為指定的class文件不在web server的classpath中(/WEB-INF/classes 和 /WEB-INF/lib)证逻。在上面的錯誤中,原因是找不到ActionForm類抗斤。
異常
javax.servlet.jsp.JspException: Exception creating bean of class org.apache.struts.action.ActionForm: {1}
可能原因
Instantiating Struts-provided ActionForm class directly instead of instantiating a class derived off ActionForm. This mightoccur implicitly if you specify that a form-bean is this Struts ActionForm class rather than specifying a child of this classfor the form-bean.
Not associating an ActionForm-descended class with an action can also lead to this error.
異常
javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection
可能原因
不是標(biāo)識Struts actionServlet的<servlet>標(biāo)記就是映射.do擴(kuò)展名的<sevlet-mapping>標(biāo)記或者兩者都沒有在web.xml中聲明囚企。
在struts-config.xml中的打字或者拼寫錯誤也可導(dǎo)致這個異常的發(fā)生。例如缺少一個標(biāo)記的關(guān)閉符號/>瑞眼。最好使用struts console工具檢查一下洞拨。
另外,load-on-startup必須在web.xml中聲明负拟,這要么是一個空標(biāo)記,要么指定一個數(shù)值歹河,這個數(shù)值用來表servlet運(yùn)行的優(yōu)先級掩浙,數(shù)值越大優(yōu)先級越低。
還有一個和使用load-on-startup有關(guān)的是使用Struts預(yù)編譯JSP文件時也可能導(dǎo)致這個異常秸歧。
異常
java.lang.NullPointerException at org.apache.struts.util.RequestUtils.forwardURL(RequestUtils.java:1223)
可能原因
在struts-config.xml中的forward元素缺少path屬性厨姚。例如應(yīng)該是如下形式:
<forward name="userhome" path="/user/userhome.jsp"/>
異常
javax.servlet.jsp.JspException: Cannot find bean org.apache.struts.taglib.html.BEAN in any scope
Probable Causes
試圖在Struts的form標(biāo)記外使用form的子元素。這常常發(fā)生在你 在</html:form>后面使用Struts的html標(biāo)記键菱。另外要注意可能你不經(jīng)意使用的無主體的標(biāo)記谬墙,如<html:form … />,這樣web 服務(wù)器解析時就當(dāng)作一個無主體的標(biāo)記经备,隨后使用的所有<html>標(biāo)記都被認(rèn)為是在這個標(biāo)記之外的拭抬,如又使用了<html:text property=”id”>還有就是在使用taglib引入HTML標(biāo)記庫時,你使用的prefix的值不是html侵蒙。
異常
javax.servlet.jsp.JspException: Missing message for key xx.xx.xx
Probable Causes
這個key的值對沒有在資源文件ApplicationResources.properties中定義造虎。如果你使用eclipse時經(jīng)常碰到這樣的情況,當(dāng)項目重新編譯時纷闺,eclipse會自動將classes目錄下的資源文件刪除算凿。
資源文件ApplicationResources.properties 不在classpath中應(yīng)將資源文件放到 WEB-INF/classes 目錄下份蝴,當(dāng)然要在struts-config.xml中定義)
異常
Cannot find message resources under key org.apache.struts.action.MESSAGE
可能原因
很顯然,這個錯誤是發(fā)生在使用資源文件時氓轰,而Struts沒有找到資源文件婚夫。
Implicitly trying to use message resources that are not available (such as using empty html:options tag instead of specifyingthe options in its body -- this assumes options are specified in ApplicationResources.properties file)
XML parser issues -- too many, too few, incorrect/incompatible versions
異常
Strange and seemingly random characters in HTML and on screen, but not in original JSP or servlet.
可能原因
混和使用Struts的html:form標(biāo)記和標(biāo)準(zhǔn)的HTML標(biāo)記不正確。
使用的編碼樣式在本頁中不支持署鸡。
異常
"Document contained no data" in Netscape
No data rendered (completely empty) page in Microsoft Internet Explorer
可能原因
使用一個Action的派生類而沒有實現(xiàn)perform()方法或execute()方法案糙。在Struts1.0中實現(xiàn)的是 perform()方法,在Struts1.1中實現(xiàn)的是execute()方法储玫,但Struts1.1向后兼容perform()方法侍筛。但你使用 Struts1.1創(chuàng)建一個Action的派生類,并且實現(xiàn)了execute()方法撒穷,而你在Struts1.0中運(yùn)行的話匣椰,就會得到"Document contained nodata" error message in Netscape or a completely empty (no HTML whatsoever) page rendered in Microsoft Internet Explorer.”的錯誤信息。
異常
ServletException: BeanUtils.populate
解決方案
在用Struts上傳文件時,遇到了javax.servlet.ServletException: BeanUtils.populate異常端礼。
我 的ActionServlet并沒有用到BeanUtils這些工具類禽笑。后來仔細(xì)檢查代碼發(fā)現(xiàn)是在jsp文件里的form忘了加 enctype="multipart/form-data" 了。所以寫程序遇到錯誤或異常應(yīng)該從多方面考慮問題存在的可能性蛤奥,想到系統(tǒng)提示信息以外的東西佳镜。
- 定義Action后, 如果指定了name, 那么必須要定義一個與它同名的FormBean才能進(jìn)行form映射.2. 如果定義Action后, 提交頁面時出現(xiàn) "No input attribute for mapping path..." 錯誤, 則需要在其input屬性中定義轉(zhuǎn)向的頁面.3. 如果插入新的數(shù)據(jù)時出現(xiàn) "Batch update row count wrong:..." 錯誤, 則說明XXX.hbm.xml中指定的key的類型為原始類型(int, long),因為這種類型會自動分配值, 而這個值往往會讓系統(tǒng)認(rèn)為已經(jīng)存在該記錄, 正確的方法是使用java.lang.Integer或java.lang.Long對象.4. 如果插入數(shù)據(jù)時出現(xiàn) "argument type mismatch" 錯誤, 可能是你使用了Date等特殊對象, 因為struts不能自動從String型轉(zhuǎn)換成Date型,所以, 你需要在Action中手動把String型轉(zhuǎn)換成Date型.5. Hibernate中, Query的iterator()比list()方法快很多.6. 如果出現(xiàn) "equal symbol expected" 錯誤, 說明你的strtus標(biāo)簽中包含另一個標(biāo)簽或者變量, 例如:
<html:select property="test" onchange="<%=test%>"/>
或者
<html:hidden property="test" value="<bean:write name="t" property="p"/>"/>
這樣的情況...
錯 誤:Exception in thread "main" org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update原因與解決: 因為Hibernate Tools(或者Eclipse本身的Database Explorer)生成.hbn.xml工具中包含有catalog="*"(表示數(shù)據(jù)庫名稱)這樣的屬性,將該屬性刪除就可以了
錯誤:org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations)
原因與解決:
方法1 刪除Set方的cascade
方法2 解決關(guān)聯(lián)關(guān)系后,再刪除
方法3 在many-to-one方增加cascade 但值不能是none
最后一招:
檢查一下hashCode equals是否使用了id作為唯一標(biāo)示的選項了凡桥;我用uuid.hex時是沒有問題的蟀伸;但是用了native,就不行了缅刽,怎么辦啊掏?刪除啊衰猛!
問 題:今天用Tomcat 5.5.12迟蜜,發(fā)現(xiàn)原來很好用的系統(tǒng)不能用了,反復(fù)測試發(fā)現(xiàn)頁面中不能包含 taglib啡省,否則會出現(xiàn)以下提示:HTTP Status 500 -type Exception reportMessage description The server encountered an internal error () that prevented it from fulfilling this request.exceptionorg.apache.jasper.JasperException: /index.jsp(1,1) Unable to read TLD "META-INF/tlds/struts-bean.tld" from JAR file"file:*****/WEB-INF/lib/struts.jar":原因:更新了工程用的lib文件夾下的jar娜睛,發(fā)布時也發(fā)布了 servlet.jar和jsp-api.jar。解決:把jsp-api.jar刪除就解決這個問題了卦睹。 -----------------------------------------------------------------------------------------------------------------------------
錯誤: java.lang.NullPointerException
原 因: 發(fā)現(xiàn) dao 實例畦戒、 manage 實例等需要注入的東西沒有被注入(俗稱空指針異常)解決:這個時候,你應(yīng)該查看日志文件结序;默認(rèn)是應(yīng)用服務(wù)器的 log 文件兢交,比如 Tomcat 就是 [Tomcat 安裝目錄 ]/logs ;你會發(fā)現(xiàn)提示你:可能是:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sf' defined in ServletContextresource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception isorg.hibernate.HibernateException: could not configure from URL: file:src/hibernate.cfg.xmlorg.hibernate.HibernateException: could not configure from URL: file:src/hibernate.cfg.xml……………………….Caused by: java.io.FileNotFoundException: src\hibernate.cfg.xml可能 是:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined inServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception isorg.hibernate.MappingException: Resource: com/mcc/coupon/model/UserRole.hbm.xml not foundorg.hibernate.MappingException: Resource: com/mcc/coupon/model/UserRole.hbm.xml not found然后你就知道原因是因為配置文件的解析出了錯誤笼痹,這個通過 Web 頁面是看不出來的配喳。更多的是持久化影射文件出的錯誤酪穿;導(dǎo)致了沒有被解析;當(dāng)然你需要的功能就無法使用了晴裹。
錯誤:StandardWrapperValve[action]: Servlet.service() for servlet action threw exception
javax.servlet.jsp.JspException: Cannot retrieve mapping for action /settlementTypeManage
或 者: type Status report message Servlet action is not available description The requested resource (Servlet action is not available) is not available.
原因: 同 上
錯 誤StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exceptionjava.lang.ClassNotFoundException: org.apache.struts.taglib.bean.CookieTei界面錯誤具體描述:
org.apache.jasper.JasperException: Failed to load or instantiate TagExtraInfo class: org.apache.struts.taglib.bean.CookieTei
原因與解決: <方案一>你的“html:”開頭的標(biāo)簽沒有放在一個<html:form>中 <方案二>重新啟動你的應(yīng)用服務(wù)器被济,自動就沒有這個問題