person attribute is stored at request scope.if you specify only type you have to specify scope of the attribute.otherwise it searches for the defalut scope("page")and didnt find any attribute so it throws exception. where as if you specify "class" then searches for all the scopes from page to application i think. Hey see the answer in page 416.you will understand well. Please correct me if i am wrong.
Joined: May 14, 2004
If I change the jsp tag "usebean" to <jsp:useBean id="person" type="other.Employee" scope="request">
Your code works fine when you use the following construct because the bean is by default only searched in Page scope and not in other scopes. As per your code you are setting the bean in request scope and hence you have to specify the scope as request while using <jsp:useBean>.
Joined: Apr 20, 2002
I think you are confusing the concepts of scope with the use of class and/or type.
Scope will define where the bean will be searched for with the default scope set to page. Type is the type of the reference variable that will be created at translation time if the bean is found in the indicated scope. Class is the class of the object that the variable (type) will point to. If your bean cannot be found in the scope which you indicated then an instance will be created if you have indicated the class an a default constructor exists for that class.
Since you did not indicate the class and told the tag to look in the default(page) scope, it could not instantiate a bean when it did not find one.
This is an important concept that is sure to be on the exam.
Try running the code with a class parameter in the useBean tag without indicating a scope and you will see that one is created for you.
I will leave understanding how/why the nested tag is executed to you :-)
Joined: Feb 18, 2007
Thanks to all ! The thing is, I had printed all the code as shown in HFJS pg: 356. In that example in the book, the request scope is not mentioned in the jsp:useBean tag, and still they say the example should run fine.
Hence I thought, there is some problem in my understanding; which is not the case.