Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Polymorphism on standard action <jsp:useBean>  RSS feed

 
Ernesto Hilvano
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
 
Stefan Evans
Bartender
Posts: 1834
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!