jQuery in Action, 2nd edition*
The moose likes Servlets and the fly likes Using jsp:useBean for a bean with one argument constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Using jsp:useBean for a bean with one argument constructor" Watch "Using jsp:useBean for a bean with one argument constructor" New topic
Author

Using jsp:useBean for a bean with one argument constructor

Celina Joseph
Greenhorn

Joined: Aug 23, 2001
Posts: 24
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.
Mikael Rundqvist
Greenhorn

Joined: Sep 18, 2001
Posts: 7
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.
------------------
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using jsp:useBean for a bean with one argument constructor