This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Reference: Chapter -8 Page 420 of new book and 416 of old book
I have following two classes
abstract class person with attribute name.
class Employee which extends Person with attribute empId.
I have following code in my servlet Person p = new Employee();
In my jsp I have:
<jsp:useBean id="personBean" type="com.example.Employee" scope="request">
<jsp:setProperty name="personBean" property="name"/>
Name is:: <jsp:getProperty name="personBean" property="name" />
If I run it, it works fine and displays Evan (which is expected according to me)
But the book at page 420 says, that it should fail at request time! The "personBean" attribute is stored at request scpde, so the <jsp:useBean> tag wont work since it specifies only a type. The container knows that if you have only a type specified there must be an existing bean attribute of that name and scope.
I dont understand why should it fail???
Am I doing anything different as it is not failing in my case??
One Point I noted is, In old book they have not specified any scope so it will by default search person in page scope so it should fail which is right,
but in new book they have specified scope="request" on <jsp:useBean> tag, so according to me it should not fail in this case.
Answer for the number 1 exercise
ANSWERS FAILS at request time! The �person� attribute is stored at request scope, so the <jsp:useBean > tag won�t work since it specifies only a type." The answer is wrong since the attribute scope is defined as request in the <jsp:useBean>. The correct would be "Prints Name is Evan."
Note from the Author or Editor:
VALID This exercise has dogged us from the beginning. It will be complete replaced in the next edition.