i was just trying the example of HFSJ page 416 of jsp:usebean, where Person is abstract class and Employee is the sub class of Person. below is the code:-
<jsp:useBean id="person" type="foo.Employee" scope="request">
<jsp:setProperty name="person" property="name" value="fred"/>
Name: <jsp:getProperty name="person" property="name"/>
foo.Person p = new foo.Employee();
request.setAttribute("person" , p);
I was expecting that output will be Name:EVAN (according to book also ), since i have used only type in jsp:usebean, so body of the jsp:usebean will not be executed but after running code on RAD 6.0 i am getting output like this:-
please explain me whats wrong with above code. Is this the correct behaviour?
Ankit Garg wrote:It must have found your bean in the request scope as since you've not given class attribute, so the container will throw an exception if the bean is not already in scope. Then the body must not get executed. Can't say what the problem is...
Yes , i given scope as request , so it found the person attribute in request scope and i didnt get any exception. But how come body got executed and property was set to another value... not sure
Is this the correct behaviour?
To make it clear, no it's not. Maybe a container bug. Try it on Tomcat 5.5.
And also, what does Employee#setName look like ? Something like :