I am reading the book Head First Servlets and Jsp. I came across the following useBean question in "scripless jsp" chapter.
jsp looks like (only relavant code is given)
foo.Person is abstract class
1) what happens if the servlet code looks like this
given answer: fails at request time
2) what happens if the servlet code looks like
given answer: sucess and prints "name is evan"
i don't understand the 2nd answer. The person attribute has request scope. As useBean didn't mention any scope page scope is considered as default.
Then 2nd scenario also should fail. Am i right?
In the 1st case object is of type Person. It won't match with the type attribute(foo.Employee) of useBean tag. Suppose if scopes match will this work.
The bean "per" is of type bean.Person. How can we print a attribute of bean.Employee. Then what is the use of type attribute in jsp:usebean.
Joined: Apr 21, 2008
Then what is the use of type attribute in jsp:usebean.
'type' is used if the corresponding bean object already available and it was set in particular scope. If our jsp invokes , container first sees is the bean is available or not? Like if it finds, it will use that, if not it will not create another bean object and body will not be executed(if present).
I am confused about inheritance effect on type field. I want to know which getter/setter methods are called if we put a bean object in request scope and mention only type (super class of actual bean object) in <jsp:useBean> tag