Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:useBean doubt

 
Devendra Joshi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In 'useBean' action, 'page' scope cannot be used when I am using 'type' attribute and not 'class' attribute.

Is this assumption correct?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why ?
 
Devendra Joshi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
scope='page' means a new instance will be created (always), whereas when we use type the object needs to be present with the given name (new object will not be created).
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The bean could be created before the useBean, although it does not make much sense
 
Devendra Joshi
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you mean to say something like this:

<%
MyBean bean = new MyBean();
page.setAttribute("thisBean", bean);
%>

<jsp:useBean id="thisBean" type="MyBean"/>
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, something like pageContext.setAttribute("thisBean", bean);. This looks pointless, doesn't it ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic