Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:useBean standard action doubt

 
prashant k. gupta
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • 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?


 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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);
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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 Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic