This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Question about <jsp:useBean...>" Watch "Question about <jsp:useBean...>" New topic
Author

Question about <jsp:useBean...>

weilong wang
Greenhorn

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
</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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

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...
 
jQuery in Action, 2nd edition
 
subject: Question about <jsp:useBean...>