2015-05-17 21 views
1

我用這本書:http://pdf.coreservlets.com/Form-Data.pdf 和話題4.7:自動填充來自請求參數的Java對象:表單bean

我想實現使用Eclipse的代碼,但它創造的問題。我嘗試了兩種方法,如下所示:如何在Eclipse中使用javabeans?

  1. 我在文件夾\coreservlets\beans中創建了文件BeanUtilities.java
  2. 我在文件夾\coreservlets\src\coreservlets\beans中創建了文件BeanUtilities.java

    • 當我使用的第一種方法則該文件在SubmitInsuranceInfo.java有此錯誤:

BeanUtilities cannot be resolved

並有在文件BeanUtilities.java沒有錯誤。

  • 但是當我用第二種方法則文件BeanUtilities.java它給這個錯誤:

The import org.apache.commons cannot be resolved

,並在文件SubmitInsuranceInfo.java沒有錯誤。

任何人都可以請給我一個解決方案。謝謝。

回答

1

BeanUtilities will not work unless you install the Jakarta Commons BeanUtils. However, since BeanUtils depends on two other Jakarta Commons components—Collections and Logging—you have to download and install all three.

下載的Jakarta Commons BeanUtilities,從這裏http://commons.apache.org/proper/commons-beanutils/ http://commons.apache.org/proper/commons-collections/ http://commons.apache.org/proper/commons-logging/

集合和記錄罐添加這些罐子到類路徑。

0

請確保您導入了需要的jar。在你的PDF示例中,還可以閱讀更多幫助你的評論。在PDF中的代碼示例中已經提到:

/**一些實用程序可以填充bean,通常基於 *傳入請求參數。需要來自Apache Commons庫的三個包 *:beanutils,集合, *和日誌記錄。要獲得這些軟件包,請參閱 * http://jakarta.apache.org/commons/。此外,這本書的 *源代碼包(見http://www.coreservlets.com/) */

感謝,

+0

能否請你告訴我在哪裏把所有的包呢?我是新手! –

+0

在你的** lib **文件夾中,看你的eclipse項目結構。複製jar文件並粘貼到eclipse的lib中。 –

0

BeanUtilities cannot be resolved

- >在文件SubmitInsuranceInfo.java必須具備:

import coreservlets.beans.BeanUtilities; 


The import org.apache.commons cannot be resolved

- >進口Commons BeanUtils。下載從here (需要文件:commons-beanutils.jar)加到您的Java Build Path & Deployment Assembly

在文件BeanUtilities.java必須具備:

import org.apache.commons.beanutils.BeanUtils;