简体   繁体   中英

How to use javabeans in Eclipse?

I am using this book: http://pdf.coreservlets.com/Form-Data.pdf and topic 4.7 is: Automatically Populating Java Objects from Request Parameters: Form Beans

I am trying to implement the code using Eclipse but it is creating problems. I have tried two ways as following:

  1. I created file BeanUtilities.java in the folder \\coreservlets\\beans .
  2. I created file BeanUtilities.java in the folder \\coreservlets\\src\\coreservlets\\beans .

    • When I used the first method then in the file SubmitInsuranceInfo.java there was this error:

BeanUtilities cannot be resolved

and there was no error in file BeanUtilities.java .

  • But when I used the second method then in the file BeanUtilities.java it is giving this error:

The import org.apache.commons cannot be resolved

and no error in file SubmitInsuranceInfo.java .

Can anyone please give me a solution. Thank you.

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.

Download Jakarta Commons BeanUtilities, Collections and Logging jars from here http://commons.apache.org/proper/commons-beanutils/ http://commons.apache.org/proper/commons-collections/ http://commons.apache.org/proper/commons-logging/

Add these jars to your class path.

Please ensure that you imported the requires jar. In your pdf example also read the comment which help you more. On the code example in PDF it is already mention:

/** Some utilities to populate beans, usually based on * incoming request parameters. Requires three packages * from the Apache Commons library: beanutils, collections, * and logging. To obtain these packages, see * http://jakarta.apache.org/commons/ . Also, the book's * source code archive (see http://www.coreservlets.com/ ) */

Thanks,

BeanUtilities cannot be resolved

--> In file SubmitInsuranceInfo.java must have:

import coreservlets.beans.BeanUtilities;


The import org.apache.commons cannot be resolved

--> Import Commons BeanUtils . Down load from here (Need file: commons-beanutils.jar ) add to your Java Build Path & Deployment Assembly .

In file BeanUtilities.java must have:

import org.apache.commons.beanutils.BeanUtils;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM