aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes jsp:useBean standard action doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "jsp:useBean standard action doubt" Watch "jsp:useBean standard action doubt" New topic
Author

jsp:useBean standard action doubt

prashant k. gupta
Ranch Hand

Joined: May 15, 2008
Posts: 62
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

How did you go from the servlet to the JSP ?


[My Blog]
All roads lead to JavaRanch
prashant k. gupta
Ranch Hand

Joined: May 15, 2008
Posts: 62
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

Joined: Aug 03, 2008
Posts: 9293
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
prashant k. gupta
Ranch Hand

Joined: May 15, 2008
Posts: 62
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: May 15, 2008
Posts: 62

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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp:useBean standard action doubt