i'm surprised, a bean to work definitely needs a zero argument constructor (which ofcourse if provided if not specified). If you have a single / multiple arg constructor and if u have forgotten to define the zero argument constructor
then the java class is not a bean. So it w'd'nt work.
Originally posted by SoonAnn Lim:
This question troubles me long time ago and i did not bother to find it out until recently. When creating a bean for jsp, my bean will work perfectly well if i don't include a constructor explicitly. If i provide a constructor for the bean, errors occur at <jsp:useBean .....>. Can somebody give me some explanation? Thanks a lot.
IF on the other hand, you supply a with-args constructor, Java assumes you know what you are doing and does not provide a default no-args constructor.
That is the odd thing i want to make it clear. I understand that default constructor will be supplied by Java supper class. However, i am confused when i supply a constructor (either with or w/o arguments) to my bean class, errors are generated. If i take off my constructor and used the default constructor from super class, everything behaves as it should. The key note is <b>Why errors are generated when i supply my constructor for my bean class?</b> Thanks for any comment.
The only thing I can think of is that, the bean class just does not expect any constructor (with/without args) to be supplied at all. So supplying one does not make it a bean.