Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Polymorphism on standard action <jsp:useBean>

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello i am reading the HFSJ now and currently i am trying to replicate its example shown below:



and the servlet code is:



Now, the HFSJ said that the result is
"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."

so i replicated it but i am not getting a failure at request time. can somebody enlighten me why?

Anyways for your reference, foo.Person is an abstract class while foo.Employee is a concrete class of foo.Person
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you go to the jsp without visiting the servlet first you will not have a "person" attribute in request scope, and so the jsp will throw an exception at that point.
It can't instantiate the bean without the "Class" attribute as it doesn't know which type to instantiate.

If you go via the servlet, and put a person into request scope, the page should work fine.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic