This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Using jsp:useBean without class attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Using jsp:useBean without class attribute" Watch "Using jsp:useBean without class attribute" New topic
Author

Using jsp:useBean without class attribute

pal sahab
Greenhorn

Joined: Feb 11, 2009
Posts: 8
This is to reference to BE THE CONTAINERON page # 358 in HF SCWCD book.

Prob:

<jsp:useBean id="person" type="foo.Employee" scope="request" >
<jsp:setProperty name="person" property="name" value="Fred" />
</jsp:useBean>
Name is : <jsp:getProperty name="person" property="name" />

1. What happens if the servlet code looks like:

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

Where Person is abstract class and Employee extends Person and is concreate class.

Explanation given :

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 the name and scope.

My Doubt

According to my understanding if the attribute ("person") is already in request scope then the <jsp:useBean> will try to find the attribute by something like this in generated _jspService method by the container.

person = (foo.Employee)_jspx_page_context.getAttribute("person",PageContext.Request_Scope);

so if person if not null then there is no point of failure at request time and <jsp:getProperty> will print the name.

Can anybody please explain where iam wrong?

Regards
Sumit Kumar
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

This is an error in the book, checkout the errata to know about this and other errors in the book...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
pal sahab
Greenhorn

Joined: Feb 11, 2009
Posts: 8
Thank you Ankit
 
jQuery in Action, 2nd edition
 
subject: Using jsp:useBean without class attribute