Forums Register Login

Question about <jsp:useBean...>

+Pie Number of slices to send: Send
Actually, this question is grabbed from p358 from the Head First Servlet & JSP, but I don't quite understand the answer. :(
If, say, I have the following action in JSP:

<jsp:useBean id="person" type="foo.Employee" scope="request">
//some code
</jsp:useBean>

and before this, I have the following code in my servlet running before forwarding the request to JSP:

foo.Person p = new foo.Employee();
p.setName("Evan");
request.setAttribute("person", p);

in which foo.Person is an abstract class and foo.Employee extends it, assuming they both works quite all right with the proper getter and setter.
I don't understand why these code would fail during request time according to the answer. It seems to me that the servlet code have set the "person"
attribute at "request" scope which can be later fetched by the <jsp:useBean...>

THANK YOU GUYS

+Pie Number of slices to send: Send
It would help to know in what way it fails. Do you get an error message? A stack trace? Those are important information for anybody who wants to understand the problem.
+Pie Number of slices to send: Send
frankly, this is a book example, I haven't rewrite the complete code and test it yet.

But according to the book, it says" it will FAIL 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".

It seems to me the "person" attribute in the "request" scope is perfectly legal, so...I just don't understand the explanation...
get schwifty. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 815 times.
Similar Threads
HFSJ: Be the Container: page 358
useBean doubt
doubt in JAVA beans
jsp:usebean
bean-related standard actions exercise
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 23:48:50.