aspose file tools*
The moose likes JSP and the fly likes doubt regarding  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "doubt regarding  "jsp:useBean "  tag" Watch "doubt regarding  "jsp:useBean "  tag" New topic
Author

doubt regarding "jsp:useBean " tag

Prakash Reddy
Greenhorn

Joined: Apr 18, 2006
Posts: 15
Hi

I have the following servlet and JSP code

---------------------Servlet---------------------------------
foo.Employee p = new foo.Employee();
p.setName("Evan");
request.setAttribute("person",p);
-------------------------------------------------------------


-------------------JSP---------------------------------------
<jsp:useBean id="person" type="foo.Employee">
</jsp:useBean>
Name is : <jsp:getProperty name="person" property="name" />
-------------------------------------------------------------


Assume that I have all the required classes and I am forwarding the request from the servlet to the jsp.
I want to know whether this will output "Name is Evan" or cause a runtime error.

I feel this wont work because the container tries to find the person object in the page scope since the default scope is "page". But since the person object is stored in the request scope ,it wont find it in the page scope and will hence try to create a new Employee object. But since I am not specifying the "class" attribute it fails to create the object. Hence we get an error.
But HeadFirst book says that this works fine and outputs "Name is Evan".

Can someone explain which one is correct and why ?


Prakash<br />(SCJP 1.4 96%)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60056
    
  65

What happened when you tried it?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt regarding "jsp:useBean " tag
 
Similar Threads
Question on Standard actions
HFS&JSP book pno-416
Is this an error in HFSJ ??
HFSJ doubt :Pg:356
Question to Kathy