jQuery in Action, 3rd edition
The moose likes JSP and the fly likes Question about <jsp:useBean...> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Question about <jsp:useBean...>" Watch "Question about <jsp:useBean...>" New topic

Question about <jsp:useBean...>

weilong wang

Joined: Jul 18, 2012
Posts: 2
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

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

foo.Person p = new foo.Employee();
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...>


Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

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.
weilong wang

Joined: Jul 18, 2012
Posts: 2
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...
I agree. Here's the link: http://aspose.com/file-tools
subject: Question about <jsp:useBean...>
It's not a secret anymore!