Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using jsp:useBean for a bean with one argument constructor

 
Celina Joseph
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
------------------
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic