Using jsp:useBean for a bean with one argument constructor
Joined: Aug 23, 2001
Hi All, I have a bean class DataTest.I have to instantiate it with useBean and specifying the scope as application. But, the constructor of DataTest needs a parameter to be passed from the JSP. Is it possible to use useBean with also specifying the constructor parameter somewhere. If not, please let me know other alternatives.
Joined: Sep 18, 2001
Hi Celina, from what I have experienced it seems that at least Tomcat requires that the class have a default constructor (e.g. a non-argument constructor). I think the definition of what a java-bean is also states that there must exist a default constructor for the class. To handle the problem you can do a work-around where you demand that jsp-pages which are to use your bean has to make a call to a method that set your internal variable the first thing they do before the bean can be used in other ways. The variable that has to be set can either come from an html form, a config file or be hard-coded in the jsp-file. See syntax for <%= and use the id of the bean that you have instantiated. ------------------