• 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

jsp:useBean standard action doubt

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ranchers,

i was just trying the example of HFSJ page 416 of jsp:usebean, where Person is abstract class and Employee is the sub class of Person. below is the code:-


jsp code



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

Name: <jsp:getProperty name="person" property="name"/>




servlet code


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




I was expecting that output will be Name:EVAN (according to book also ), since i have used only type in jsp:usebean, so body of the jsp:usebean will not be executed but after running code on RAD 6.0 i am getting output like this:-

Name: fred


please explain me whats wrong with above code. Is this the correct behaviour?


 
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
How did you go from the servlet to the JSP ?
 
prashant k. gupta
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christophe Verré wrote:How did you go from the servlet to the JSP ?



using RequestDispatcher in servlet:-

request.getRequestDispatcher("signup.jsp").forward(request,response);
 
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
It must have found your bean in the request scope as since you've not given class attribute, so the container will throw an exception if the bean is not already in scope. Then the body must not get executed. Can't say what the problem is...
 
prashant k. gupta
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:It must have found your bean in the request scope as since you've not given class attribute, so the container will throw an exception if the bean is not already in scope. Then the body must not get executed. Can't say what the problem is...



Yes , i given scope as request , so it found the person attribute in request scope and i didnt get any exception. But how come body got executed and property was set to another value... not sure
 
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

Is this the correct behaviour?


To make it clear, no it's not. Maybe a container bug. Try it on Tomcat 5.5.

And also, what does Employee#setName look like ? Something like :
 
prashant k. gupta
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


And also, what does Employee#setName look like ? Something like :

\


yes its same. I have this method in Person class (super class of Employee class)
 
reply
    Bookmark Topic Watch Topic
  • New Topic