国产在线精品一区二区三区,中文字幕日韩专区,麻豆影视在线http://www.aygfsteel.com/keweibo/category/25676.html一專 Java 多能 Delphi,Powerbuilder ... zh-cnThu, 22 Dec 2011 02:42:04 GMTThu, 22 Dec 2011 02:42:04 GMT60java.io.CharConversionException: Not an ISO 8859-1 character: xxhttp://www.aygfsteel.com/keweibo/articles/366938.htmlKeKeWed, 21 Dec 2011 07:26:00 GMThttp://www.aygfsteel.com/keweibo/articles/366938.htmlhttp://www.aygfsteel.com/keweibo/comments/366938.htmlhttp://www.aygfsteel.com/keweibo/articles/366938.html#Feedback0http://www.aygfsteel.com/keweibo/comments/commentRss/366938.htmlhttp://www.aygfsteel.com/keweibo/services/trackbacks/366938.html
這個問題是因為outputstream輸出中文字造成的.換成Writer就好了。outputstream是以字節為單位輸出字符串的,需要符合那個ISO 8859-1編碼

response.setContentType("text/html;charset=UTF-8");
//response.getOutputStream().print("中文字"); //這行會出錯
response.getWriter().print("中文字"); //換成這個就好了
response.getWriter().close();




Ke 2011-12-21 15:26 發表評論
]]>
[Microsoft][ODBC 驅動程序管理器] 驅動程序的 SQLAllocHandle on SQL_HANDLE_ENV 失敗http://www.aygfsteel.com/keweibo/articles/289716.htmlKeKeTue, 04 Aug 2009 02:28:00 GMThttp://www.aygfsteel.com/keweibo/articles/289716.htmlhttp://www.aygfsteel.com/keweibo/comments/289716.htmlhttp://www.aygfsteel.com/keweibo/articles/289716.html#Feedback0http://www.aygfsteel.com/keweibo/comments/commentRss/289716.htmlhttp://www.aygfsteel.com/keweibo/services/trackbacks/289716.html 環境變量path值
%JAVA_HOME%\bin;%CATALINA_HOME%\bin;D:\oracle\ora92\bin;D:\oracle\isuite\jdk\jre\bin\classic;D:\oracle\isuite\jdk\jre\bin;D:\oracle\isuite\jdk\jre\bin\client;D:\oracle\isuite\jlib;D:\oracle\isuite\bin;D:\oracle\isuite\jre\1.1.8\bin;C:\Program Files\Oracle\jre\1.3.1\bin;C:\Program Files\Oracle\jre\1.1.8\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem
因為昨天又安裝了一個Oracle客戶端,今天發現ODBC就無法使用了,老是提示“[Microsoft][ODBC   驅動程序管理器]   驅動程序的   SQLAllocHandle   on   SQL_HANDLE_ENV   失敗”之類的錯誤信息,把紅色部份調到path值的最前面,成功解決問題!


Ke 2009-08-04 10:28 發表評論
]]>
解決在eclipse項目中使用utf-8字符時導出錯誤http://www.aygfsteel.com/keweibo/articles/288671.htmlKeKeTue, 28 Jul 2009 01:17:00 GMThttp://www.aygfsteel.com/keweibo/articles/288671.htmlhttp://www.aygfsteel.com/keweibo/comments/288671.htmlhttp://www.aygfsteel.com/keweibo/articles/288671.html#Feedback0http://www.aygfsteel.com/keweibo/comments/commentRss/288671.htmlhttp://www.aygfsteel.com/keweibo/services/trackbacks/288671.html 我以前網上找到的辦法都不好,解決的辦法其實十分簡單
在build.properties文件中加入

javacDefaultEncoding.. = UTF-8

Ke 2009-07-28 09:17 發表評論
]]>
getOutputStream() has already been called for this responsehttp://www.aygfsteel.com/keweibo/articles/287882.htmlKeKeWed, 22 Jul 2009 09:14:00 GMThttp://www.aygfsteel.com/keweibo/articles/287882.htmlhttp://www.aygfsteel.com/keweibo/comments/287882.htmlhttp://www.aygfsteel.com/keweibo/articles/287882.html#Feedback0http://www.aygfsteel.com/keweibo/comments/commentRss/287882.htmlhttp://www.aygfsteel.com/keweibo/services/trackbacks/287882.html
朋友在處理Jsp時, 希望能夠將產生好的excel檔案能夠下載到Client 端
但要將產生好的file利用 SmartUpload 下載時, 發生以下問題
getOutputStream() has already been called for this response
後來找到了解決方法如下:
<範例>
@page contentType="text/html; charset=big5" 
@page session
="true" errorPage="error.jsp"
 
@page 
import="com.jspsmart.upload.*"
 
String ret 
= request.getParameter("ret"
);
if (ret != null
) { 
ret 
=
 java.net.URLDecoder.decode(ret);
ret 
= new String(ret.getBytes("8859_1"),"Big5"
);
}
else ret = ""
;
String file 
= request.getParameter("file"
);
if (file != null
) {
file 
=
 java.net.URLDecoder.decode(file);
file 
= new String(file.getBytes("8859_1"),"Big5"
);
else file = ""
;
// 新建一個SmartUpload對象 

SmartUpload su1 = new SmartUpload();
// 初始化

su1.initialize(pageContext);
//
 設定contentDisposition為null以禁止瀏覽器自動打開文件,
//
保證點擊鏈接後是下載文件。若不設定,則下載的文件擴展名為 
//
doc時,瀏覽器將自動用word打開它。擴展名為pdf時, 
//瀏覽器將用acrobat打開。

su1.setContentDisposition(null);
// 下載文件

su1.downloadFile(file);

問題原因:Tomcat首先執行.jsp, Tomcat準備好session, out等object。 而在< % ... % >段中,HttpServerletResponse的getOutputStream()方法已被呼叫。但在JSP規中定義此方法只能被使用一 次,這樣在產生out時會在使用一次, 因此會出錯。
網路上建議方法: 不要使用Jsp, 改使用Servlet就不會有此問題
後來有人回應在最後加入兩行
out.clear();
out = pageContext.pushBody();
果然解決了這個問題!!


Ke 2009-07-22 17:14 發表評論
]]>
exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of XXXhttp://www.aygfsteel.com/keweibo/articles/186597.htmlKeKeSun, 16 Mar 2008 04:41:00 GMThttp://www.aygfsteel.com/keweibo/articles/186597.htmlhttp://www.aygfsteel.com/keweibo/comments/186597.htmlhttp://www.aygfsteel.com/keweibo/articles/186597.html#Feedback3http://www.aygfsteel.com/keweibo/comments/commentRss/186597.htmlhttp://www.aygfsteel.com/keweibo/services/trackbacks/186597.html     (XXX為某個set方法名)
     當查詢結果中某列值為null,而持久類中對應的屬性為primitive類型時,則會拋出此異常。

Ke 2008-03-16 12:41 發表評論
]]>
java.lang.IllegalAccessError: tried to access method net.sf.ehcache.CacheManager.<init>()V from class org.hibernate.cache.EhCacheProviderhttp://www.aygfsteel.com/keweibo/articles/175619.htmlKeKeWed, 16 Jan 2008 02:36:00 GMThttp://www.aygfsteel.com/keweibo/articles/175619.htmlhttp://www.aygfsteel.com/keweibo/comments/175619.htmlhttp://www.aygfsteel.com/keweibo/articles/175619.html#Feedback3http://www.aygfsteel.com/keweibo/comments/commentRss/175619.htmlhttp://www.aygfsteel.com/keweibo/services/trackbacks/175619.html java.lang.IllegalAccessError: tried to access method net.sf.ehcache.CacheManager.<init>()V from class org.hibernate.cache.EhCacheProvider
此類錯誤錯誤信息,上網上查了一下.大概了解了下,原來是JAR文件版本問題,
The latest hibernate uses ehcache 1.2 - you seem to be using an older version (1.1 maybe). Upgrade your ehcache library and report back if you still have problems.

原來項目中使用了ehcache-1.1.jar文件,
把它換成ehcache-1.2.3.jar文件后,
重新啟動JBOSS服務器,問題解決~~~~

Ke 2008-01-16 10:36 發表評論
]]>
log4j:ERROR A "org.jboss.logging.util.OnlyOnceErrorHandler" object is not assignable to a "org.apache.log4j.spi.ErrorHandler" variable的異常http://www.aygfsteel.com/keweibo/articles/175618.htmlKeKeWed, 16 Jan 2008 02:30:00 GMThttp://www.aygfsteel.com/keweibo/articles/175618.htmlhttp://www.aygfsteel.com/keweibo/comments/175618.htmlhttp://www.aygfsteel.com/keweibo/articles/175618.html#Feedback0http://www.aygfsteel.com/keweibo/comments/commentRss/175618.htmlhttp://www.aygfsteel.com/keweibo/services/trackbacks/175618.htmllog4j是一個很好的開源的日志項目,下面就我在實際中使用的一些情況作一個小結(我所寫的是以spring為框架的運用,之所以要提到這點,是因為在spring中專門有處理log4j的地方,而我也用到了這些地方)。

 在使用的第一步你要明白你所發布的web項目所使用的服務器,因為不同的服務器對于使用log4j是有些不同的,我在實際使用中主要是用tomcat和jboss兩類,對于tomcat,它本身是沒有配置log4j的,所以使用起來和常規的一樣;而在jboss中它是本身配置了log4j的,所以有時候我們在看項目代碼時,其整個項目并沒有log4j的配置文件,而在一些類中仍然定義了Logger,例如static Logger log = org.apache.log4j.Logger.getLogger(UserDaoImple.class);,這就表明開發者打算使用jboss默認的log4j的配置,我們可以在jboss下的對應的log目錄下的server.log中看到日志,jboss本身的log4j的配置是將debug,info級的日志寫在server.log中,而像error等級別比較高的日志打印到控制臺上,而寫到server.log中的日志比較多,并不方便查看。于是我們想到使用自己的log4j配置寫到某個具體的文件中(注意文件要先建立,才能忘里面寫東西,log4j自己不能建立文件),但這里因為jboss有它自己的log4j配置,所以如果我們配置的log4j包含Console的Appender時,就會出錯,錯誤類似于

ERROR: invalid console appender config detected, console stream is looping.
解決方法一是不用Console的Appender,或者改jboss的配置文件,在jboss-service.xml文件里,把
<mbean code="org.jboss.logging.Log4jService" name="jboss.system:type=Log4jService,service=Logging">
        <attribute name="ConfigurationURL">resource:log4j.xml</attribute>
        <attribute name="CatchSystemOut">false</attribute>
        <attribute name="Log4jQuietMode">true</attribute>
</mbean>。

我建議不用Console的Appender,當然這是對jboss3.2.x是這樣,對于jboss4.0.x如果我們要用自己的log4j配置照上述改還是會有問題,會有類似于log4j:ERROR A "org.jboss.logging.util.OnlyOnceErrorHandler" object is not assignable to a "org.apache.log4j.spi.ErrorHandler" variable的異常,解決方法是把/server/default/jbossweb-tomcat55.sar/META-INF/jboss-service.xml 中的以下兩個熟悉改成true
<attribute name="Java2ClassLoadingCompliance">true</attribute>
<attribute name="UseJBossWebLoader">true</attribute>

以上就是使用jboss服務器可能出現的問題,解決了這些再來使用log4j就比較簡單了。

下面說說對于采用了spring框架的項目如何使用log4j,在spring中使用log4j,有些方便的地方,

1. 動態的改變記錄級別和策略,即修改log4j.properties,不需要重啟Web應用,這需要在web.xml中設置一下。
2. 把log文件定在 /WEB-INF/logs/ 而不需要寫絕對路徑。
3. 可以把log4j.properties和其他properties一起放在/WEB-INF/ ,而不是Class-Path。

首先我們在web.xml中需要設定一下

<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>WEB-INF/log4j.properties</param-value>
</context-param>

<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>60000</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener> 
其中第二部分就是能夠動態修改log4j.properties的關鍵,容器會每60秒掃描log4j的配置文件 。
對于log4j的配置文件如何寫,這就不多說了,大家可以去google,有一點就是我們如果用RollingFileAppender或者FileAppender時,可以通過${webapp.root}來定位到服務器的發布的該項目下,這是spring把web目錄的路徑壓入到了webapp.root的系統變量。然后,在log4j.properties 里就可以這樣定義logfile位置
log4j.appender.logfile.File=${webapp.root}/WEB-INF/logs/myfuse.log
如果有多個web應用,怕webapp.root變量重復,可以在context-param里定義webAppRootKey。

當我們定義完log4j.properties后,剩下的就是在需要記錄的class中new 出Logger了



Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1067141



Ke 2008-01-16 10:30 發表評論
]]>
struts2中使用displayTags的問題(ParametersInterceptor - [setParameters]: Unexpected Exception)http://www.aygfsteel.com/keweibo/articles/161226.htmlKeKeSat, 17 Nov 2007 07:21:00 GMThttp://www.aygfsteel.com/keweibo/articles/161226.htmlhttp://www.aygfsteel.com/keweibo/comments/161226.htmlhttp://www.aygfsteel.com/keweibo/articles/161226.html#Feedback11http://www.aygfsteel.com/keweibo/comments/commentRss/161226.htmlhttp://www.aygfsteel.com/keweibo/services/trackbacks/161226.html ERROR - ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'd-49653-p' on 'class dgut.ke.actions.SubjectAction: Error setting expression 'd-49653-p' with value '[Ljava.lang.String;@d73256'

在網上的搜了一下,在一些中文網頁上幾乎都找不到相關的信息,結果在一個英語網站上看到了以下信息:

I use struts2.0.9 and displaytag,xwork-2.0.4.jar,when I click next page of
displaytag,it will raise flowing warning:

Warn: ParametersInterceptor - [setParameters]: Unexpected Exception caught
setting 'd-1332698-p' on 'class Test.TestAction: Error setting expression
'd-1332698-p' with value '[Ljava.lang.String;@14bf534'
RE:
It's a warning that occurs because you're using displaytags.

Don't worry about it, it won't hurt you, and messing with it will just make
bad things happen (you know the kind of thing, long nights trying to work
out things like why table sorting isn't working, why data isn't being
displayed, and why the world is so unfair).

In the words of a nice policeman; "Move along, there's nothing to see here"

-----Original Message-----
From: red phoenix [mailto:rodphoenix@...]
Sent: 26 September 2007 16:29
To: Struts Users Mailing List
Subject: Error: ParametersInterceptor - [setParameters]


I use struts2.0.9 and displaytag,xwork-2.0.4.jar,when I click next page of
displaytag,it will raise flowing warning:

Warn: ParametersInterceptor - [setParameters]: Unexpected Exception caught
setting 'd-1332698-p' on 'class Test.TestAction: Error setting expression
'd-1332698-p' with value '[Ljava.lang.String;@14bf534'

Why raise above waring? How to solve it?
Thanks!
Add the following line to your struts.xml file.
d-.*-p

Example:
        <interceptor-stack name="creditDefaultStack">
                <interceptor-ref name="creditException" />
                <interceptor-ref name="alias" />
                <interceptor-ref name="servlet-config" />
                <interceptor-ref name="prepare" />
                <interceptor-ref name="i18n" />
                <interceptor-ref name="chain" />
                <interceptor-ref name="debugging" />
                <interceptor-ref name="profiling" />
                <interceptor-ref name="scoped-model-driven" />
                <interceptor-ref name="model-driven" />
                <interceptor-ref name="checkbox" />
                <interceptor-ref name="static-params" />
                <interceptor-ref name="params">
                        dojo\..*
                        d-.*-p </interceptor-ref>
                <interceptor-ref name="conversionError" />
                <interceptor-ref name="validation">
               
  cancel,execute,delete,edit,list,start
               
                </interceptor-ref>
                <interceptor-ref name="workflow">
                       
                                input,back,cancel,browse
                       
                </interceptor-ref>
                    </interceptor-stack>
                </interceptors>
                <default-interceptor-ref name="creditDefaultStack" />
照上面的說法去做,由于本人能力有限,還是未能解決.去下個高點的版本試試看,期待能解決!



Ke 2007-11-17 15:21 發表評論
]]>
申明式事務和OpenSessionInView http://www.aygfsteel.com/keweibo/articles/161067.htmlKeKeFri, 16 Nov 2007 08:51:00 GMThttp://www.aygfsteel.com/keweibo/articles/161067.htmlhttp://www.aygfsteel.com/keweibo/comments/161067.htmlhttp://www.aygfsteel.com/keweibo/articles/161067.html#Feedback0http://www.aygfsteel.com/keweibo/comments/commentRss/161067.htmlhttp://www.aygfsteel.com/keweibo/services/trackbacks/161067.htmlWrite operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.

今天在做事務測試的時候,控制臺輸出了以上的錯誤信息,在網上找了一下,原來是我在web.xml
文件中設置了OpenSessionInView .  將設置去掉就可以了.
<!-- OpenSessionInView -->
  <filter>
   <filter-name>OpenSessionInViewFilter</filter-name>
   <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
  </filter>
  <filter-mapping>
   <filter-name>OpenSessionInViewFilter</filter-name>
   <url-pattern>*.action</url-pattern>
  </filter-mapping>
或者加上事務設置

<?xml version="1.0" encoding="UTF-8"?>
<beans
 xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="
 http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
 http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"
 >
 <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
 
 <tx:advice id="txAdvice" transaction-manager="transactionManager">
  <tx:attributes>
   <tx:method name="create*" propagation="REQUIRED"/>
   <tx:method name="update*" propagation="REQUIRED"/>
   <tx:method name="delete*" propagation="REQUIRED"/>
   <tx:method name="find*" propagation="REQUIRED" read-only="true"/>
   <tx:method name="*" read-only="true"/>
  </tx:attributes>
 </tx:advice>
 
 <aop:config>
  <aop:pointcut id="daoOperation" expression="execution(* dgut.ke.dao.*.*(..))"/>
  <aop:advisor advice-ref="txAdvice" pointcut-ref="daoOperation"/>
 </aop:config>
 
</beans>

網上又說
盡管Open Session In View看起來還不錯,其實副作用不少。看回上面OpenSessionInViewFilter的doFilterInternal方法代碼,這個方法實際上是被父類的doFilter調用的,因此,我們可以大約了解的OpenSessionInViewFilter調用流程: request(請求)->open session并開始transaction->controller->View(Jsp)->結束transaction并close session.

     一切看起來很正確,尤其是在本地開發測試的時候沒出現問題,但試想下如果流程中的某一步被阻塞的話,那在這期間connection就一直被占用而不釋放。最有可能被阻塞的就是在寫Jsp這步,一方面可能是頁面內容大,response.write的時間長,另一方面可能是網速慢,服務器與用戶間傳輸時間久。當大量這樣的情況出現時,就有連接池連接不足,造成頁面假死現象。

Open Session In View是個雙刃劍,放在公網上內容多流量大的網站請慎用。




Ke 2007-11-16 16:51 發表評論
]]>
表字段使用了關鍵字導致數據插入發生異常http://www.aygfsteel.com/keweibo/articles/160270.htmlKeKeTue, 13 Nov 2007 09:07:00 GMThttp://www.aygfsteel.com/keweibo/articles/160270.htmlhttp://www.aygfsteel.com/keweibo/comments/160270.htmlhttp://www.aygfsteel.com/keweibo/articles/160270.html#Feedback0http://www.aygfsteel.com/keweibo/comments/commentRss/160270.htmlhttp://www.aygfsteel.com/keweibo/services/trackbacks/160270.html WARN - SQL Error: 1064, SQLState: 42000
ERROR - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'show, updateTime, id) values ('2c9ab2d51637c2ca0116380396f80009', '2c9ab2d516382' at line 1
ERROR - Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
    ... 144 more
ERROR - Servlet.service() for servlet default threw exception
java.sql.BatchUpdateException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'show, updateTime, id) values ('2c9ab2d51637c2ca0116380396f80009', '2c9ab2d516382' at line 1
    at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1103)
    at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:853)
    at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
   ........
    at java.lang.Thread.run(Thread.java:595)

原因:show 在mysql數據中為關鍵字



Ke 2007-11-13 17:07 發表評論
]]>
document.getelementbyid has no propertieshttp://www.aygfsteel.com/keweibo/articles/156247.htmlKeKeFri, 26 Oct 2007 13:04:00 GMThttp://www.aygfsteel.com/keweibo/articles/156247.htmlhttp://www.aygfsteel.com/keweibo/comments/156247.htmlhttp://www.aygfsteel.com/keweibo/articles/156247.html#Feedback0http://www.aygfsteel.com/keweibo/comments/commentRss/156247.htmlhttp://www.aygfsteel.com/keweibo/services/trackbacks/156247.html閱讀全文

Ke 2007-10-26 21:04 發表評論
]]>
struts + spring + hibernate整合事務配置的問題(請教高手)http://www.aygfsteel.com/keweibo/articles/150830.htmlKeKeSun, 07 Oct 2007 05:36:00 GMThttp://www.aygfsteel.com/keweibo/articles/150830.htmlhttp://www.aygfsteel.com/keweibo/comments/150830.htmlhttp://www.aygfsteel.com/keweibo/articles/150830.html#Feedback1http://www.aygfsteel.com/keweibo/comments/commentRss/150830.htmlhttp://www.aygfsteel.com/keweibo/services/trackbacks/150830.html一個關于struts + spring + hibernate整合事務配置的問題(請教高手)
... ...
<?xml version="1.0" encoding="UTF-8"?>
<beans
 xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

 <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
 
 <bean id="txProxyTemplate" abstract="true"
    class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
  <property name="transactionManager" ref="transactionManager"></property>
  <property name="transactionAttributes">
   <props>
    <prop key="create*">PROPAGATION_REQUIRED</prop>
    <prop key="update*">PROPAGATION_REQUIRED</prop>
    <prop key="delete*">PROPAGATION_REQUIRED</prop>
    <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
   </props>
  </property>
 </bean>
 
 <bean id="userDAO" class="dgut.ke.dao.impl.UserDAO">
      <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
<bean id="userService"  parent="txProxyTemplate"  class="dgut.ke.service.impl.UserService">
    <property name="userDAO" ref="userDAO" />
</bean>
... ....
啟動Tomecat時出了錯.之前沒有添加事務處理時.上面的代碼是可以正常運行的.添加事務之后卻出現以下錯誤
ERROR - Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in ServletContext resource [/WEB-INF/applicationContext-hibernate.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'transactionManager' of bean class [dgut.ke.service.impl.UserService]: Bean property 'transactionManager' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Caused by:
org.springframework.beans.NotWritablePropertyException: Invalid property 'transactionManager' of bean class [dgut.ke.service.impl.UserService]: Bean property 'transactionManager' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
解決辦法

<bean id="userService"  parent="txProxyTemplate"  class="dgut.ke.service.impl.UserService">
    <property name="userDAO" ref="userDAO" />
</bean>
換成以下代碼就可以正常運行了
 <bean id="userService" parent="txProxyTemplate">
      <property name="target">
           <bean class="dgut.ke.service.impl.UserService">
                <property name="userDAO" ref="userDAO"></property>
           </bean>
      </property>
 </bean>

請教一下為什么會出現這種情況?
哪位高手解釋下,謝謝!!!

Ke 2007-10-07 13:36 發表評論
]]>
struts2 interceptor 問題(請教高手)http://www.aygfsteel.com/keweibo/articles/150747.htmlKeKeSat, 06 Oct 2007 13:54:00 GMThttp://www.aygfsteel.com/keweibo/articles/150747.htmlhttp://www.aygfsteel.com/keweibo/comments/150747.htmlhttp://www.aygfsteel.com/keweibo/articles/150747.html#Feedback0http://www.aygfsteel.com/keweibo/comments/commentRss/150747.htmlhttp://www.aygfsteel.com/keweibo/services/trackbacks/150747.html今天寫了一個自定義攔截器.卻遇到了以下問題

package dgut.ke.interceptors;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

import dgut.ke.model.Catalog;
import dgut.ke.model.Publish;
import dgut.ke.model.Subject;
import dgut.ke.service.ICatalogService;
import dgut.ke.service.IPublishService;
import dgut.ke.service.ISubjectService;

public class AddBookInterceptor extends MethodFilterInterceptor {

 /**
  *
  */
 private static final long serialVersionUID = 1135497226250835266L;

 private ISubjectService subjectService ;
 private ICatalogService catalogService ;
 private IPublishService publishService ;

 public ICatalogService getCatalogService() {
  return catalogService;
 }

 public IPublishService getPublishService() {
  return publishService;
 }

 public ISubjectService getSubjectService() {
  return subjectService;
 }

 public void setCatalogService(ICatalogService catalogService) {
  this.catalogService = catalogService;
 }

 public void setPublishService(IPublishService publishService) {
  this.publishService = publishService;
 }

 public void setSubjectService(ISubjectService subjectService) {
  this.subjectService = subjectService;
 }

 @Override
 protected String doIntercept(ActionInvocation invoation) throws Exception {
  // TODO 自動生成方法存根
  System.out.println("-------- 攔截器開始執行 ----------");
  List<Subject> subject_list = (ArrayList<Subject>)subjectService.findAll();
  List<Catalog> catalog_list = (ArrayList<Catalog>)catalogService.findAll();
  List<Publish> pubish_list =  (ArrayList<Publish>)publishService.findAll();

  //ActionContext act = ActionContext.getContext() ;
  ActionContext act = invocation.getInvocationContext() ;
  HttpServletRequest request = (HttpServletRequest) act.get(ServletActionContext.HTTP_REQUEST) ;
  request.setAttribute("subject_list", subject_list) ;
  request.setAttribute("catalog_list", catalog_list) ;
  request.setAttribute("publish_list", pubish_list) ;
  System.out.println("-------- 攔截器執行結束 ----------");
  return Action.INPUT;
 }

}
為了實現request.setAttribute(String str, Object obj) ;.最先是讓上面的類實現ServletRequestAware 接口.
但是在運行的時候卻出現了空指針異常。后來改成以上的代碼就可以正常運行,但是還是
不太明白
曾經在一本書上看到一段話:構建interceptor最重要的原則:interceptor必須是無狀態的,并且不能
夠使用任何ActionInvocation提供范圍以外的API



Ke 2007-10-06 21:54 發表評論
]]>
一篇不錯的講解Java異常的文章(轉載)----感覺很不錯,讀了以后很有啟發 http://www.aygfsteel.com/keweibo/articles/148895.htmlKeKeThu, 27 Sep 2007 13:58:00 GMThttp://www.aygfsteel.com/keweibo/articles/148895.htmlhttp://www.aygfsteel.com/keweibo/comments/148895.htmlhttp://www.aygfsteel.com/keweibo/articles/148895.html#Feedback0http://www.aygfsteel.com/keweibo/comments/commentRss/148895.htmlhttp://www.aygfsteel.com/keweibo/services/trackbacks/148895.html 

六種異常處理的陋習

你覺得自己是一個Java專家嗎?是否肯定自己已經全面掌握了Java的異常處理機制?在下面這段代碼中,你能夠迅速找出異常處理的六個問題嗎?

1 OutputStreamWriter out = ...
2 java.sql.Connection conn = ...
3 try { // ⑸
4  Statement stat = conn.createStatement();
5  ResultSet rs = stat.executeQuery(
6   "select uid, name from user");
7  while (rs.next())
8  {
9   out.println("ID:" + rs.getString("uid") // ⑹
10    ",姓名:" + rs.getString("name"));
11  }
12  conn.close(); // ⑶
13  out.close();
14 }
15 catch(Exception ex) // ⑵
16 {
17  ex.printStackTrace(); //⑴,⑷
18 }


  作為一個Java程序員,你至少應該能夠找出兩個問題。但是,如果你不能找出全部六個問題,請繼續閱讀本文。

  本文討論的不是Java異常處理的一般性原則,因為這些原則已經被大多數人熟知。我們要做的是分析各種可稱為“反例”(anti-pattern)的違背優秀編碼規范的常見壞習慣,幫助讀者熟悉這些典型的反面例子,從而能夠在實際工作中敏銳地察覺和避免這些問題。

  反例之一:丟棄異常

  代碼:15行-18行。

  這段代碼捕獲了異常卻不作任何處理,可以算得上Java編程中的殺手。從問題出現的頻繁程度和禍害程度來看,它也許可以和C/C++程序的一個惡名遠播的問題相提并論??不檢查緩沖區是否已滿。如果你看到了這種丟棄(而不是拋出)異常的情況,可以百分之九十九地肯定代碼存在問題(在極少數情況下,這段代碼有存在的理由,但最好加上完整的注釋,以免引起別人誤解)。

  這段代碼的錯誤在于,異常(幾乎)總是意味著某些事情不對勁了,或者說至少發生了某些不尋常的事情,我們不應該對程序發出的求救信號保持沉默和無動于衷。調用一下printStackTrace算不上“處理異常”。不錯,調用printStackTrace對調試程序有幫助,但程序調試階段結束之后,printStackTrace就不應再在異常處理模塊中擔負主要責任了。

  丟棄異常的情形非常普遍。打開JDK的ThreadDeath類的文檔,可以看到下面這段說明:“特別地,雖然出現ThreadDeath是一種‘正常的情形’,但ThreadDeath類是Error而不是Exception的子類,因為許多應用會捕獲所有的Exception然后丟棄它不再理睬。”這段話的意思是,雖然ThreadDeath代表的是一種普通的問題,但鑒于許多應用會試圖捕獲所有異常然后不予以適當的處理,所以JDK把ThreadDeath定義成了Error的子類,因為Error類代表的是一般的應用不應該去捕獲的嚴重問題。可見,丟棄異常這一壞習慣是如此常見,它甚至已經影響到了Java本身的設計。

  那么,應該怎樣改正呢?主要有四個選擇:

  1、處理異常。針對該異常采取一些行動,例如修正問題、提醒某個人或進行其他一些處理,要根據具體的情形確定應該采取的動作。再次說明,調用printStackTrace算不上已經“處理好了異常”。

  2、重新拋出異常。處理異常的代碼在分析異常之后,認為自己不能處理它,重新拋出異常也不失為一種選擇。

  3、把該異常轉換成另一種異常。大多數情況下,這是指把一個低級的異常轉換成應用級的異常(其含義更容易被用戶了解的異常)。

  4、不要捕獲異常。

  結論一:既然捕獲了異常,就要對它進行適當的處理。不要捕獲異常之后又把它丟棄,不予理睬。

  反例之二:不指定具體的異常

  代碼:15行。

  許多時候人們會被這樣一種“美妙的”想法吸引:用一個catch語句捕獲所有的異常。最常見的情形就是使用catch(Exception ex)語句。但實際上,在絕大多數情況下,這種做法不值得提倡。為什么呢?

  要理解其原因,我們必須回顧一下catch語句的用途。catch語句表示我們預期會出現某種異常,而且希望能夠處理該異常。異常類的作用就是告訴Java編譯器我們想要處理的是哪一種異常。由于絕大多數異常都直接或間接從java.lang.Exception派生,catch(Exception ex)就相當于說我們想要處理幾乎所有的異常。

  再來看看前面的代碼例子。我們真正想要捕獲的異常是什么呢?最明顯的一個是SQLException,這是JDBC操作中常見的異常。另一個可能的異常是IOException,因為它要操作OutputStreamWriter。顯然,在同一個catch塊中處理這兩種截然不同的異常是不合適的。如果用兩個catch塊分別捕獲SQLException和IOException就要好多了。這就是說,catch語句應當盡量指定具體的異常類型,而不應該指定涵蓋范圍太廣的Exception類。

  另一方面,除了這兩個特定的異常,還有其他許多異常也可能出現。例如,如果由于某種原因,executeQuery返回了null,該怎么辦?答案是讓它們繼續拋出,即不必捕獲也不必處理。實際上,我們不能也不應該去捕獲可能出現的所有異常,程序的其他地方還有捕獲異常的機會??直至最后由JVM處理。

  結論二:在catch語句中盡可能指定具體的異常類型,必要時使用多個catch。不要試圖處理所有可能出現的異常。

  反例之三:占用資源不釋放

  代碼:3行-14行。

  異常改變了程序正常的執行流程。這個道理雖然簡單,卻常常被人們忽視。如果程序用到了文件、Socket、JDBC連接之類的資源,即使遇到了異常,也要正確釋放占用的資源。為此,Java提供了一個簡化這類操作的關鍵詞finally。

  finally是樣好東西:不管是否出現了異常,Finally保證在try/catch/finally塊結束之前,執行清理任務的代碼總是有機會執行。遺憾的是有些人卻不習慣使用finally。

  當然,編寫finally塊應當多加小心,特別是要注意在finally塊之內拋出的異常??這是執行清理任務的最后機會,盡量不要再有難以處理的錯誤。

  結論三:保證所有資源都被正確釋放。充分運用finally關鍵詞。

反例之四:不說明異常的詳細信息

  代碼:3行-18行。

  仔細觀察這段代碼:如果循環內部出現了異常,會發生什么事情?我們可以得到足夠的信息判斷循環內部出錯的原因嗎?不能。我們只能知道當前正在處理的類發生了某種錯誤,但卻不能獲得任何信息判斷導致當前錯誤的原因。

  printStackTrace的堆棧跟蹤功能顯示出程序運行到當前類的執行流程,但只提供了一些最基本的信息,未能說明實際導致錯誤的原因,同時也不易解讀。

  因此,在出現異常時,最好能夠提供一些文字信息,例如當前正在執行的類、方法和其他狀態信息,包括以一種更適合閱讀的方式整理和組織printStackTrace提供的信息。

  結論四:在異常處理模塊中提供適量的錯誤原因信息,組織錯誤信息使其易于理解和閱讀。

  反例之五:過于龐大的try塊

  代碼:3行-14行。

  經常可以看到有人把大量的代碼放入單個try塊,實際上這不是好習慣。這種現象之所以常見,原因就在于有些人圖省事,不愿花時間分析一大塊代碼中哪幾行代碼會拋出異常、異常的具體類型是什么。把大量的語句裝入單個巨大的try塊就象是出門旅游時把所有日常用品塞入一個大箱子,雖然東西是帶上了,但要找出來可不容易。

  一些新手常常把大量的代碼放入單個try塊,然后再在catch語句中聲明Exception,而不是分離各個可能出現異常的段落并分別捕獲其異常。這種做法為分析程序拋出異常的原因帶來了困難,因為一大段代碼中有太多的地方可能拋出Exception。

  結論五:盡量減小try塊的體積。

  反例之六:輸出數據不完整

  代碼:7行-11行。

  不完整的數據是Java程序的隱形殺手。仔細觀察這段代碼,考慮一下如果循環的中間拋出了異常,會發生什么事情。循環的執行當然是要被打斷的,其次,catch塊會執行??就這些,再也沒有其他動作了。已經輸出的數據怎么辦?使用這些數據的人或設備將收到一份不完整的(因而也是錯誤的)數據,卻得不到任何有關這份數據是否完整的提示。對于有些系統來說,數據不完整可能比系統停止運行帶來更大的損失。

  較為理想的處置辦法是向輸出設備寫一些信息,聲明數據的不完整性;另一種可能有效的辦法是,先緩沖要輸出的數據,準備好全部數據之后再一次性輸出。

  結論六:全面考慮可能出現的異常以及這些異常對執行流程的影響。

  改寫后的代碼

  根據上面的討論,下面給出改寫后的代碼。也許有人會說它稍微有點?嗦,但是它有了比較完備的異常處理機制。

OutputStreamWriter out = ...
java.sql.Connection conn = ...
try {
 Statement stat = conn.createStatement();
 ResultSet rs = stat.executeQuery(
  "select uid, name from user");
 while (rs.next())
 {
  out.println("ID:" + rs.getString("uid") + ",姓名: " + rs.getString("name"));
 }
}
catch(SQLException sqlex)
{
 out.println("警告:數據不完整");
 throw new ApplicationException("讀取數據時出現SQL錯誤", sqlex);
}
catch(IOException ioex)
{
 throw new ApplicationException("寫入數據時出現IO錯誤", ioex);
}
finally
{
 if (conn != null) {
  try {
   conn.close();
  }
  catch(SQLException sqlex2)
  {
   System.err(this.getClass().getName() + ".mymethod - 不能關閉數據庫連接: " + sqlex2.toString());
  }
 }

 if (out != null) {
  try {
   out.close();
  }
  catch(IOException ioex2)
  {
   System.err(this.getClass().getName() + ".mymethod - 不能關閉輸出文件" + ioex2.toString());
  }
 }
}

  本文的結論不是放之四海皆準的教條,有時常識和經驗才是最好的老師。如果你對自己的做法沒有百分之百的信心,務必加上詳細、全面的注釋。

  另一方面,不要笑話這些錯誤,不妨問問你自己是否真地徹底擺脫了這些壞習慣。即使最有經驗的程序員偶爾也會誤入歧途,原因很簡單,因為它們確確實實帶來了“方便”。所有這些反例都可以看作Java編程世界的惡魔,它們美麗動人,無孔不入,時刻誘惑著你。也許有人會認為這些都屬于雞皮蒜毛的小事,不足掛齒,但請記住:勿以惡小而為之,勿以善小而不為。





------------------------------------------------------------------下面是一些java異常集-------------------------------------------------------------------------------------------


算術異常類:ArithmeticExecption

空指針異常類:NullPointerException

類型強制轉換異常:ClassCastException

數組負下標異常:NegativeArrayException

數組下標越界異常:ArrayIndexOutOfBoundsException

違背安全原則異常:SecturityException

文件已結束異常:EOFException

文件未找到異常:FileNotFoundException

字符串轉換為數字異常:NumberFormatException


操作數據庫異常:SQLException


輸入輸出異常:IOException


方法未找到異常:NoSuchMethodException

java.lang.AbstractMethodError

抽象方法錯誤。當應用試圖調用抽象方法時拋出。

java.lang.AssertionError

斷言錯。用來指示一個斷言失敗的情況。

java.lang.ClassCircularityError

類循環依賴錯誤。在初始化一個類時,若檢測到類之間循環依賴則拋出該異常。

java.lang.ClassFormatError

類格式錯誤。當Java虛擬機試圖從一個文件中讀取Java類,而檢測到該文件的內容不符合類的有效格式時拋出。

java.lang.Error

錯誤。是所有錯誤的基類,用于標識嚴重的程序運行問題。這些問題通常描述一些不應被應用程序捕獲的反常情況。

java.lang.ExceptionInInitializerError

初始化程序錯誤。當執行一個類的靜態初始化程序的過程中,發生了異常時拋出。靜態初始化程序是指直接包含于類中的static語句段。

java.lang.IllegalAccessError

違法訪問錯誤。當一個應用試圖訪問、修改某個類的域(Field)或者調用其方法,但是又違反域或方法的可見性聲明,則拋出該異常。

java.lang.IncompatibleClassChangeError

不兼容的類變化錯誤。當正在執行的方法所依賴的類定義發生了不兼容的改變時,拋出該異常。一般在修改了應用中的某些類的聲明定義而沒有對整個應用重新編譯而直接運行的情況下,容易引發該錯誤。

java.lang.InstantiationError

實例化錯誤。當一個應用試圖通過Java的new操作符構造一個抽象類或者接口時拋出該異常.

java.lang.InternalError

內部錯誤。用于指示Java虛擬機發生了內部錯誤。

java.lang.LinkageError

鏈接錯誤。該錯誤及其所有子類指示某個類依賴于另外一些類,在該類編譯之后,被依賴的類改變了其類定義而沒有重新編譯所有的類,進而引發錯誤的情況。

java.lang.NoClassDefFoundError

未找到類定義錯誤。當Java虛擬機或者類裝載器試圖實例化某個類,而找不到該類的定義時拋出該錯誤。

java.lang.NoSuchFieldError

域不存在錯誤。當應用試圖訪問或者修改某類的某個域,而該類的定義中沒有該域的定義時拋出該錯誤。

java.lang.NoSuchMethodError

方法不存在錯誤。當應用試圖調用某類的某個方法,而該類的定義中沒有該方法的定義時拋出該錯誤。

java.lang.OutOfMemoryError

內存不足錯誤。當可用內存不足以讓Java虛擬機分配給一個對象時拋出該錯誤。

java.lang.StackOverflowError

堆棧溢出錯誤。當一個應用遞歸調用的層次太深而導致堆棧溢出時拋出該錯誤。

java.lang.ThreadDeath

線程結束。當調用Thread類的stop方法時拋出該錯誤,用于指示線程結束。

java.lang.UnknownError

未知錯誤。用于指示Java虛擬機發生了未知嚴重錯誤的情況。

java.lang.UnsatisfiedLinkError

未滿足的鏈接錯誤。當Java虛擬機未找到某個類的聲明為native方法的本機語言定義時拋出。

java.lang.UnsupportedClassVersionError

不支持的類版本錯誤。當Java虛擬機試圖從讀取某個類文件,但是發現該文件的主、次版本號不被當前Java虛擬機支持的時候,拋出該錯誤。

java.lang.VerifyError

驗證錯誤。當驗證器檢測到某個類文件中存在內部不兼容或者安全問題時拋出該錯誤。

java.lang.VirtualMachineError

虛擬機錯誤。用于指示虛擬機被破壞或者繼續執行操作所需的資源不足的情況。


java.lang.ArithmeticException

算術條件異常。譬如:整數除零等。

java.lang.ArrayIndexOutOfBoundsException

數組索引越界異常。當對數組的索引值為負數或大于等于數組大小時拋出。

java.lang.ArrayStoreException

數組存儲異常。當向數組中存放非數組聲明類型對象時拋出。

java.lang.ClassCastException

類造型異常。假設有類A和B(A不是B的父類或子類),O是A的實例,那么當強制將O構造為類B的實例時拋出該異常。該異常經常被稱為強制類型轉換異常。

java.lang.ClassNotFoundException

找不到類異常。當應用試圖根據字符串形式的類名構造類,而在遍歷CLASSPAH之后找不到對應名稱的class文件時,拋出該異常。

java.lang.CloneNotSupportedException

不支持克隆異常。當沒有實現Cloneable接口或者不支持克隆方法時,調用其clone()方法則拋出該異常。

java.lang.EnumConstantNotPresentException

枚舉常量不存在異常。當應用試圖通過名稱和枚舉類型訪問一個枚舉對象,但該枚舉對象并不包含常量時,拋出該異常。

java.lang.Exception

根異常。用以描述應用程序希望捕獲的情況。

java.lang.IllegalAccessException

違法的訪問異常。當應用試圖通過反射方式創建某個類的實例、訪問該類屬性、調用該類方法,而當時又無法訪問類的、屬性的、方法的或構造方法的定義時拋出該異常。

java.lang.IllegalMonitorStateException

違法的監控狀態異常。當某個線程試圖等待一個自己并不擁有的對象(O)的監控器或者通知其他線程等待該對象(O)的監控器時,拋出該異常。

java.lang.IllegalStateException

違法的狀態異常。當在Java環境和應用尚未處于某個方法的合法調用狀態,而調用了該方法時,拋出該異常。

java.lang.IllegalThreadStateException

違法的線程狀態異常。當縣城尚未處于某個方法的合法調用狀態,而調用了該方法時,拋出異常。

java.lang.IndexOutOfBoundsException

索引越界異常。當訪問某個序列的索引值小于0或大于等于序列大小時,拋出該異常。

java.lang.InstantiationException

實例化異常。當試圖通過newInstance()方法創建某個類的實例,而該類是一個抽象類或接口時,拋出該異常。

java.lang.InterruptedException

被中止異常。當某個線程處于長時間的等待、休眠或其他暫停狀態,而此時其他的線程通過Thread的interrupt方法終止該線程時拋出該異常。

java.lang.NegativeArraySizeException

數組大小為負值異常。當使用負數大小值創建數組時拋出該異常。

java.lang.NoSuchFieldException

屬性不存在異常。當訪問某個類的不存在的屬性時拋出該異常。

java.lang.NoSuchMethodException

方法不存在異常。當訪問某個類的不存在的方法時拋出該異常。

java.lang.NullPointerException

空指針異常。當應用試圖在要求使用對象的地方使用了null時,拋出該異常。譬如:調用null對象的實例方法、訪問null對象的屬性、計算null對象的長度、使用throw語句拋出null等等。

java.lang.NumberFormatException

數字格式異常。當試圖將一個String轉換為指定的數字類型,而該字符串確不滿足數字類型要求的格式時,拋出該異常。

java.lang.RuntimeException

運行時異常。是所有Java虛擬機正常操作期間可以被拋出的異常的父類。

java.lang.SecurityException

安全異常。由安全管理器拋出,用于指示違反安全情況的異常。

java.lang.StringIndexOutOfBoundsException

字符串索引越界異常。當使用索引值訪問某個字符串中的字符,而該索引值小于0或大于等于序列大小時,拋出該異常。

java.lang.TypeNotPresentException

類型不存在異常。當應用試圖以某個類型名稱的字符串表達方式訪問該類型,但是根據給定的名稱又找不到該類型是拋出該異常。該異常與ClassNotFoundException的區別在于該異常是unchecked(不被檢查)異常,而ClassNotFoundException是checked(被檢查)異常。

java.lang.UnsupportedOperationException

不支持的方法異常。指明請求的方法不被支持情況的異常。

異常
javax.servlet.jsp.JspException: Cannot retrieve mapping for action /Login (/Login是你的action名字)  

可能原因
action沒有再struts-config.xml 中定義,或沒有找到匹配的action,例如在JSP文件中使用 <html:form action="Login.do".將表單提交給Login.do處理,如果出現上述異常,請查看struts-config.xml中的定義部分,有時可能是打錯了字符或者是某些不符合規則,可以使用strutsconsole工具來檢查。
-----------------------------------------------------------------------------------------------------------------
異常
org.apache.jasper.JasperException: Cannot retrieve definition for form bean null

可能原因     
      
這個異常是因為Struts根據struts-config.xml中的mapping沒有找到action期望的form bean。大部分的情況可能是因為在form-bean中設置的name屬性和action中設置的name屬性不匹配所致。換句話說,action和form都應該各自有一個name屬性,并且要精確匹配,包括大小寫。這個錯誤當沒有name屬性和action關聯時也會發生,如果沒有在action中指定name屬性,那么就沒有name屬性和action相關聯。當然當action制作某些控制時,譬如根據參數值跳轉到相應的jsp頁面,而不是處理表單數據,這是就不用name屬性,這也是action的使用方法之一。
-----------------------------------------------------------------------------------------------------------------
異常
No action instance for path /xxxx could be created

可能原因
特別提示:因為有很多中情況會導致這個錯誤的發生,所以推薦大家調高你的web服務器的日志/調試級別,這樣可以從更多的信息中看到潛在的、在試圖創建action類時發生的錯誤,這個action類你已經在struts-config.xml中設置了關聯(即添加了<action>標簽)。

在struts-config.xml中通過action標簽的class屬性指定的action類不能被找到有很多種原因,例如:定位編譯后的.class文件失敗。Failure to place compiled .class file for the action in the classpath (在web開發中,class的的位置在r WEB-INF/classes,所以你的action class必須要在這個目錄下。例如你的action類位于WEB-INF/classes/action/Login.class,那么在struts-config.xml中設置action的屬性type時就是action.Login).
拼寫錯誤,這個也時有發生,并且不易找到,特別注意第一個字母的大小寫和包的名稱。
-----------------------------------------------------------------------------------------------------------------
異常
javax.servlet.jsp.JspException: No getter method for property username of bean org.apache.struts.taglib.html.BEAN

可能原因
沒有位form bean中的某個變量定義getter 方法

這個錯誤主要發生在表單提交的FormBean中,用struts標記<html:text property=”username”>時,在FormBean中必須有一個getUsername()方法。注意字母“U”。
-----------------------------------------------------------------------------------------------------------------
異常
java.lang.NoClassDefFoundError: org/apache/struts/action/ActionForm

可能原因
這個錯誤主要發生在在classpath中找不到相應的Java .class文件。如果這個錯誤發生在web應用程序的運行時,主要是因為指定的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

可能原因
不是標識Struts actionServlet的<servlet>標記就是映射.do擴展名的<sevlet-mapping>標記或者兩者都沒有在web.xml中聲明。

在struts-config.xml中的打字或者拼寫錯誤也可導致這個異常的發生。例如缺少一個標記的關閉符號/>。最好使用struts console工具檢查一下。

另外,load-on-startup必須在web.xml中聲明,這要么是一個空標記,要么指定一個數值,這個數值用來表servlet運行的優先級,數值越大優先級越低。

還有一個和使用load-on-startup有關的是使用Struts預編譯JSP文件時也可能導致這個異常。
-----------------------------------------------------------------------------------------------------------------
異常
java.lang.NullPointerException at org.apache.struts.util.RequestUtils.forwardURL(RequestUtils.java:1223)

可能原因
在struts-config.xml中的forward元素缺少path屬性。例如應該是如下形式:
<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標記外使用form的子元素。這常常發生在你在</html:form>后面使用Struts的html標記。另外要注意可能你不經意使用的無主體的標記,如<html:form … />,這樣web 服務器解析時就當作一個無主體的標記,隨后使用的所有<html>標記都被認為是在這個標記之外的,如又使用了<html:text property=”id”>還有就是在使用taglib引入HTML標記庫時,你使用的prefix的值不是html。
-----------------------------------------------------------------------------------------------------------------
異常
javax.servlet.jsp.JspException: Missing message for key xx.xx.xx

Probable Causes
這個key的值對沒有在資源文件ApplicationResources.properties中定義。如果你使用eclipse時經常碰到這樣的情況,當項目重新編譯時,eclipse會自動將classes目錄下的資源文件刪除。

資源文件ApplicationResources.properties 不在classpath中應將資源文件放到 WEB-INF/classes 目錄下,當然要在struts-config.xml中定義)
-----------------------------------------------------------------------------------------------------------------
異常
Cannot find message resources under key org.apache.struts.action.MESSAGE

可能原因
很顯然,這個錯誤是發生在使用資源文件時,而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標記和標準的HTML標記不正確。

使用的編碼樣式在本頁中不支持。
-----------------------------------------------------------------------------------------------------------------
異常
"Document contained no data" in Netscape

No data rendered (completely empty) page in Microsoft Internet Explorer

可能原因
使用一個Action的派生類而沒有實現perform()方法或execute()方法。在Struts1.0中實現的是perform()方法,在Struts1.1中實現的是execute()方法,但Struts1.1向后兼容perform()方法。但你使用Struts1.1創建一個Action的派生類,并且實現了execute()方法,而你在Struts1.0中運行的話,就會得到"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這些工具類。后來仔細檢查代碼發現是在jsp文件里的form忘了加enctype=&quot;multipart/form-data&quot; 了。所以寫程序遇到錯誤或異常應該從多方面考慮問題存在的可能性,想到系統提示信息以外的東西。
----------------------------------------------------------------------------------------------------------------------------
1. 定義Action后, 如果指定了name, 那么必須要定義一個與它同名的FormBean才能進行form映射.2. 如果定義Action后, 提交頁面時出現 "No input attribute for mapping path..." 錯誤, 則需要在其input屬性中定義轉向的頁面.3. 如果插入新的數據時出現 "Batch update row count wrong:..." 錯誤, 則說明XXX.hbm.xml中指定的key的類型為原始類型(int, long),因為這種類型會自動分配值, 而這個值往往會讓系統認為已經存在該記錄, 正確的方法是使用java.lang.Integer或java.lang.Long對象.4. 如果插入數據時出現 "argument type mismatch" 錯誤, 可能是你使用了Date等特殊對象, 因為struts不能自動從String型轉換成Date型,所以, 你需要在Action中手動把String型轉換成Date型.5. Hibernate中, Query的iterator()比list()方法快很多.6. 如果出現 "equal symbol expected" 錯誤, 說明你的strtus標簽中包含另一個標簽或者變量, 例如:
<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="***"(*表示數據庫名稱)這樣的屬性,將該屬性刪除就可以了
---------------------------------------------------------------------------------------------------------------------------
錯誤:org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations)
原因與解決:
方法1 刪除Set方的cascade
方法2 解決關聯關系后,再刪除
方法3 在many-to-one方增加cascade 但值不能是none
最后一招:
檢查一下hashCode equals是否使用了id作為唯一標示的選項了;我用uuid.hex時是沒有問題的;但是用了native,就不行了,怎么辦?刪除啊!
----------------------------------------------------------------------------------------------------------------------------
問題:今天用Tomcat 5.5.12,發現原來很好用的系統不能用了,反復測試發現頁面中不能包含 taglib,否則會出現以下提示: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,發布時也發布了servlet.jar和jsp-api.jar。解決:把jsp-api.jar刪除就解決這個問題了。-----------------------------------------------------------------------------------------------------------------------------
錯誤: java.lang.NullPointerException
原因: 發現 dao 實例、 manage 實例等需要注入的東西沒有被注入(俗稱空指針異常)解決:這個時候,你應該查看日志文件;默認是應用服務器的 log 文件,比如 Tomcat 就是 [Tomcat 安裝目錄 ]/logs ;你會發現提示你:可能是: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 頁面是看不出來的。更多的是持久化影射文件出的錯誤;導致了沒有被解析;當然你需要的功能就無法使用了。
----------------------------------------------------------------------------------------------------------------------------
錯誤: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:”開頭的標簽沒有放在一個<html:form>中       <方案二>重新啟動你的應用服務器,自動就沒有這個問題



Ke 2007-09-27 21:58 發表評論
]]>
java.lang.IllegalArgumentException: sessionFactory or hibernateTemplate is requiredhttp://www.aygfsteel.com/keweibo/articles/145545.htmlKeKeSun, 16 Sep 2007 08:45:00 GMThttp://www.aygfsteel.com/keweibo/articles/145545.htmlhttp://www.aygfsteel.com/keweibo/comments/145545.htmlhttp://www.aygfsteel.com/keweibo/articles/145545.html#Feedback6http://www.aygfsteel.com/keweibo/comments/commentRss/145545.htmlhttp://www.aygfsteel.com/keweibo/services/trackbacks/145545.html
昨天在做一個SSH的例子時.啟動TOMCAT服務器時就老是報錯.
.........
java.lang.IllegalArgumentException: sessionFactory or hibernateTemplate is required

根據提示在配置文件中為這個類添加一個property屬性
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
就不會報錯.但是其它的Service類并不需要這么做,讓我感覺很奇怪.最終發現原來是我讓CataogService  extends HibernateDaoSupport .改正后運行正常,goood
牢記....



Ke 2007-09-16 16:45 發表評論
]]>
傳參數時id=${user.id }和id='${user.id }'http://www.aygfsteel.com/keweibo/articles/143565.htmlKeKeSat, 08 Sep 2007 02:18:00 GMThttp://www.aygfsteel.com/keweibo/articles/143565.htmlhttp://www.aygfsteel.com/keweibo/comments/143565.htmlhttp://www.aygfsteel.com/keweibo/articles/143565.html#Feedback0http://www.aygfsteel.com/keweibo/comments/commentRss/143565.htmlhttp://www.aygfsteel.com/keweibo/services/trackbacks/143565.html 

 <font color="red"><html:errors property="org.apache.struts.action.GLOBAL_MESSAGE"/></font>
     <form action="browseUser" method="post">
      <table border="1">
       <tr>
        <th>用戶名</th><th>密碼</th><th>真實姓名</th><th>出生日期</th><th>電子郵件</th><th>刪除</th>
       </tr>
      <c:forEach items="${browse_user_list}" var="user">
       <tr>
        <td>${user.username}</td>
        <td>${user.password}</td>
        <td>${user.truename}</td>
        <td>${user.birthday}</td>
        <td>${user.email}</td>
        <td>
         <a onclick="return confirm('確實要刪除?')" href="deleteUser.do?id=${user.id }">刪除</a>
        </td>
       </tr>      </c:forEach>
      </table>
昨天晚上由于把id=${user.id }寫成了id='${user.id }'.結果在action里.接收到的id參數的值的形式為 ' 5424ga54g5a4fgafasf ' ,多了一對單引號,老是報空指針異常.這樣寫
導致了在查詢數據庫時查不到相應的對象,因為在數據庫里根本就沒有id=' 5424ga54g5a4fgafasf ' 這樣的記錄存在.


Ke 2007-09-08 10:18 發表評論
]]>
javax.servlet.ServletException: DispatchMapping[XXX] does not define a handler property http://www.aygfsteel.com/keweibo/articles/143543.htmlKeKeFri, 07 Sep 2007 16:37:00 GMThttp://www.aygfsteel.com/keweibo/articles/143543.htmlhttp://www.aygfsteel.com/keweibo/comments/143543.htmlhttp://www.aygfsteel.com/keweibo/articles/143543.html#Feedback1http://www.aygfsteel.com/keweibo/comments/commentRss/143543.htmlhttp://www.aygfsteel.com/keweibo/services/trackbacks/143543.html

錯誤 :javax.servlet.ServletException: DispatchMapping[0] does not define a handler property
原因: action參數配置不全
解決方法:在 config文件中 添加 parameter="method"等

錯誤: 表單數據驗證失敗時發生錯誤,“No input attribute for mapping path”
原因:action中表單驗證 validate="true" ,如果validate()返回非空的ActionErrors,將會被轉到input屬性指定的URI,而action中未指定input時會報此錯
解決方法:添加 input="url" 或者 validate="false"

錯誤:jsp頁面中,一個form有隱藏的method屬性,<input type="hidden" name="method" value="<bean:message key="button.deleteall"/>"> ,當其他的button使用 method時會默認為使用該屬性,則達不到程序員預期的操作
解決方法:實用javascript寫一個function,改變該method值
function{
document.forms[0].elements.value="你要的操作名";

}

錯誤:Action里無法解析 導入的包,Form里的方法,但是代碼沒錯
原因:不明,我是改變了validation.xml后重新發布而出了錯的
解決方法:將工程關了,再打開,myeclipse會將工程重新構建,這樣問題就解決了
ps:重啟Tomcat是沒有用滴……

錯誤:Struts:HTTP Status 404 - Servlet action is not available

   原因 1.、web.xml文件中未配置ActionServlet。      
   2、struts-config.xml文件未配置你要訪問的Action。   
    3、你的jsp文件form標記中action屬性的路徑名稱錯誤。   
    4、非以上三種情況。

針對以上4種情況相應的解決方案如下:   
    
   1、在web.xml文件中加上ActionServlet的配置信息   
    
   <servlet>   
           <servlet-name>action</servlet-name>   
           <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>   
           <init-param>   
               <param-name>config</param-name>   
               <param-value>/WEB-INF/struts-config.xml</param-value>   
           </init-param>   
           <init-param>   
               <param-name>debug</param-name>   
               <param-value>0</param-value>   
           </init-param>   
           <init-param>   
               <param-name>detail</param-name>   
               <param-value>0</param-value>   
           </init-param>   
           <load-on-startup>2</load-on-startup>   
       </servlet>       
    
   2、在struts-config.xml文件檢查你要訪問的Action配置文件。   
    
   3、檢查jsp文件form標記中action屬性的路徑名稱是否與struts-config.xml文件中action標記的path屬性的路徑名稱一致。   
    
   4、非以上情況的解決辦法就是檢查web容器的log日志,如果時tomcat則檢查下logs目錄下的localhost_log文件,看里邊是否記錄有錯誤信息,然后根據錯誤信息提示將其糾正。



Ke 2007-09-08 00:37 發表評論
]]>
MyEclipse 開發 SSH 整合時 java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit 解決方案 http://www.aygfsteel.com/keweibo/articles/140086.htmlKeKeMon, 27 Aug 2007 10:43:00 GMThttp://www.aygfsteel.com/keweibo/articles/140086.htmlhttp://www.aygfsteel.com/keweibo/comments/140086.htmlhttp://www.aygfsteel.com/keweibo/articles/140086.html#Feedback1http://www.aygfsteel.com/keweibo/comments/commentRss/140086.htmlhttp://www.aygfsteel.com/keweibo/services/trackbacks/140086.htmlMyEclipse 開發 SSH 整合時 java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit 解決方案

這篇文章解決了問題, 核心提示:

2007-08-08 發現用 MyEclipse 5.5 做 Struts 1.2 + Spring 2.0 + Hibernate 3.1 整合時啟動過程中報如下的錯誤:


2007-08-08 15:36:17,406 ERROR [org.hibernate.proxy.BasicLazyInitializer] - CGLIB Enhancement failed: dao.User
java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit(IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)V
 at net.sf.cglib.core.ClassEmitter.begin_class(ClassEmitter.java:77)

Spring 和 Hibernate 共用的一些 jar 文件發生了版本沖突, 刪除 WEB-INF/lib/asm-2.2.3.jar 然后重啟 Tomcat.

asm-2.2.3.jar
       asm.jar
       asm-attrs.jar
      asm-commons-2.2.3.jar
      asm-util-2.2.3.jar

原文參考: http://heweiya.javaeye.com/blog/101575



Ke 2007-08-27 18:43 發表評論
]]>
java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool異常的解決辦法http://www.aygfsteel.com/keweibo/articles/139377.htmlKeKeSun, 26 Aug 2007 01:31:00 GMThttp://www.aygfsteel.com/keweibo/articles/139377.htmlhttp://www.aygfsteel.com/keweibo/comments/139377.htmlhttp://www.aygfsteel.com/keweibo/articles/139377.html#Feedback1http://www.aygfsteel.com/keweibo/comments/commentRss/139377.htmlhttp://www.aygfsteel.com/keweibo/services/trackbacks/139377.html一啟動Tomcat服務器就出了一大堆異常
報的錯誤是java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool
在網上查找錯誤的原因,說是缺少了一個commons-pool.jar文件
在myeclipse的安裝目錄下搜索,得到這個文件.放進lib文件夾.
問題解決!

Ke 2007-08-26 09:31 發表評論
]]>
主站蜘蛛池模板: 澄城县| 曲周县| 津南区| 增城市| 竹山县| 凉城县| 重庆市| 盘锦市| 桂阳县| 洪江市| 澄城县| 巴楚县| 玛纳斯县| 南平市| 来宾市| 安顺市| 璧山县| 平安县| 德钦县| 兴安县| 江门市| 宿迁市| 顺平县| 特克斯县| 贵阳市| 新乡县| 板桥市| 安顺市| 依兰县| 巴林右旗| 贵德县| 集贤县| 辰溪县| 正镶白旗| 新兴县| 昌黎县| 双城市| 偃师市| 平武县| 巴塘县| 峨眉山市|