wood burning stoves*
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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
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: 61457
    
  67

What happened when you tried it?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: doubt regarding "jsp:useBean " tag