This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
<jsp:useBean id=”person” type=”foo.Employee” scope=”request” >
<jsp:setProperty name=”person” property=”name” value=”Fred” />
Name is: <jsp:getProperty name=”person” property=”name” />
Now imagine that is Servlet does some work and then forwards the request to the JSP that has the code above. Figure out what the JSP code above would do for each of the three different servlet code examples. (The answer is given at the page no : 420)
foo.Person p = new foo.Employee();
answer is :
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 container knows that if you have only a type specified there must be an existing bean attribute of that name and scope.
my prob :
sinch the "person" attribute already exists in request scope that is set by servlet code.
then why it will fail at request time.
but why <jsp:useBean> tag won't work.
i have studied in page no : 356 of 2nd edition head first jsp & servlet book that
heading using type without class if the persn attribute already exists in that scope
it works perpectly
if the person attribute does not exist in that scope
then java.lang.InstantiationException: bean person not fund within socpe