• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Using jsp:useBean without class attribute

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is an error in the book, checkout the errata to know about this and other errors in the book...
 
pal sahab
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Ankit
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic