• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt in HFS ..in Script fre jsp chapter

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
In Page 420 HFS there is a question :
<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” />


What happens if the servlet code looks like:
foo.Person p = new foo.Employee();
p.setName(“Evan”);
request.setAttribute(“person”, p);

Its says:
The body will NEVER
run! It’s pointless to
put a body inside a <jsp:
useBean > tag if you have
only a type and no class!
Remember, the tag body
executes ONLY if a new
bean is created, which can
never happen when only
a type (but no class)
is
declared in the tag.


But Now since the person attribute is already present ,so when the beanid is checked it wil know that in request scope the person is there ,so there is no point in creating a bean , an dthrowing an error that class is not specified?


Thanks
Amarshi Mohanty
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

an dthrowing an error that class is not specified?


Why should it throw an error ? If the person is already there, it will use it. If the person was not there, that would be a problem.
 
amarshi mohanty
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well the book says:
"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 that name and scope".
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But the useBean tag uses scope="request". So it will look in the request scope, find the employee, and print its name. There seems to be some contradiction here. Did you check the errata ?
 
amarshi mohanty
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christophe Verré wrote:But the useBean tag uses scope="request". So it will look in the request scope, find the employee, and print its name. There seems to be some contradiction here. Did you check the errata ?




Well they missed....
but as per concept it shud not fail rite?.
thankx
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic