• Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt in jsp:useBean

 
Praveen Joseph
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<jsp:useBean id="user" type="foo.utils.User">
</jsp:useBean>

<jsp:getProperty name="user" property="name"/>

If the servlet which forwards request to this Jsp is as below

User user = new Admin();
user.setName("John");
request.setAttribute("user",user);

will this work?
 
Mirko Bonasorte
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
no, you would get a bean into request scope put by the servlet, and another one into the page scope put by the jsp.
You should set the scope in your standard action <jsp:useBean>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paveen Joseph:
will this work?


Why don't you just test it out?
 
Mirko Bonasorte
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ops, a little correction: your <useBean> lacks the attribute 'class' or 'beanName', so it can not create the missing object in the page scope.

Please, mercy!
 
Praveen Joseph
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the reply.

I tried it out. I am getting an Error which says :bean don't exist in the scope.

I just wanted to confirm this as the book Head First Servlets and JSP says that the above code will work.
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you posted exactly what the book states, then it's probably a typo. The default scope is page if one is not specified on the usebean tag.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!