• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about <jsp:useBean...>

 
weilong wang
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Paul Clapham
Sheriff
Pie
Posts: 20978
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic