Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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

jsp:useBean Doubt

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have some JSP code:

<jsp:useBean id="person" type="foo.Employee">
<jsp:setProperty name="person" property="name" value="Fred" />
</jsp:useBean>


I have the following servlet code which does some work and forwards the request to the above JSP:

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


Now, this scenario is supposed to fail (as explained in Head First Servlets and Jsp book, Chapter is Scriptless Jsp). Can someone please explain to me why should it fail ? If we use only the type attribute the bean should already exist and I think the following line is doing that :
request.setAttribute("person",p);
 
Praveen Sharma
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to add to my question "Person" is an abstract class and "Employee" is a non-abstract class.
 
Ranch Hand
Posts: 166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Deepa

Check this post https://coderanch.com/t/177608/java-Web-Component-SCWCD/certification/useBean

Srividhya
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by deepak valechha:
.. If we use only the type attribute the bean should already exist and I think the following line is doing that :
request.setAttribute("person",p);



The bean exists in the request scope. But the useBean action looks in the page scope, since the scope attribute is missing and page scope is the default.
 
Praveen Sharma
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jan !!
 
Destroy anything that stands in your way. Except this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic