Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt regarding "jsp:useBean " tag

 
Prakash Reddy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened when you tried it?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic