Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A knowledge to share

 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello rancher,

I have got below details to share with all Just have a look it might help to clear doubts of <useBean> tag


answer is 1.

Detailed Explanation

1. The only requirement for a class to be used as a bean in a JSP page is that the class should have a public no-args constructor, so the the JSP engine can instantiate the class. The following the the relevent postion of the code generated by tomcat for this page:

try
{
myint = (java.lang.String) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "java.lang.String");

}
catch (ClassNotFoundException exc)
{
throw new InstantiationException(exc.getMessage());
}
catch (Exception exc)
{
throw new ServletException (" Cannot create bean of class "+"java.lang.Integer", exc);
}

The String class has a no args constructor, so an empty string object is created.
2. The jsp:setProperty action in this question tries to set all the properties of the bean from the values present in the request. However, the String class does not have any method named setMystring() and so the page prints "".






 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic