• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jsp:get and setProperty doubt?

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys,

Can we use jsp:getProperty and jsp:setProperty without using a jsp:useBean?
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope.. The reason is very simple, we always use <jsp:setProperty> standard action tag to set the property values of certain JavaBean. So without specifying JavaBean's name, it wouldn't be possible to set the desired values of JavaBean's properties and that's why name and property attributes are mandatory in <jsp:setProperty> tag. The same is applicable for <jsp:getProperty> standard action tag. Before using these two tags, we need to declare and instantiate the JavaBean class by using <jsp:useBean .../> tag in our jsp's. e.g. <jsp:useBean id="myBean" type="classtype" class="xxx.ClassName" scope="session" />. id attribute of <jsp:useBean.../> is the object-name which we use in name attribute of <jsp:setProperty> & <jsp:getProperty> tags to specify the JavaBean name.


Hope this helps!!!

Thanks,
Mahesh

--------------------
SCJP 1.4 | SCWCD 1.4 | SCBCD 1.3 | SCEA Part I - In Progress
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I read from David Bridgewater's book that we can!
 
Mahesh Desai
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How...? Could you please explain it...?
 
Mahesh Desai
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How...? Could you please explain it...?
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what David Bridgewater's book says,

Actually, the truth is that you can use <jsp:setProperty> and <jsp:getProperty> without a previous <jsp:useBean>. All <jsp:setProperty> and <jsp:getProperty> do is to use PageContext.findAttribute()�so if an attribute of the right name exists�set up, perhaps, in a previous servlet�these standard actions will fi nd it. However, it�s good practice to
include <jsp:useBean> before these actions in the same JSP page. After all,
it won�t replace beans of the same name that you have set up by other means,
and it will create beans of the right name that don�t exist already. Furthermore, if your <jsp:setProperty> and <jsp:getProperty> standard actions try to access an attribute that doesn�t exist, they
are liable to die a horrible death with HTTP 500 errors returned to the requester.
 
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what section JSP.5.3 of the specification says:


The value of the name attribute in jsp:setProperty and jsp:getProperty will
refer to an object that is obtained from the pageContext object through its findAttribute method.
The object named by the name must have been �introduced� to the JSP processor using either the jsp:useBean action or a custom action with an
associated VariableInfo entry for this name. If the object was not introduced in this manner, the container implementation is recommended (but not required) to raise a translation error, since the page implementation is in violation of the specification.

Note � A consequence of the previous paragraph is that objects that are stored in, say, the session by a front component are not automatically visible to jsp:setProperty and jsp:getProperty actions in that page unless a jsp:useBean action, or some other action, makes them visible.



I have tested it in tomcat and a transaltion error is thrown.
 
Mahesh Desai
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for more details on this topic guys!!!

Mahesh
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sergio,

Thanks for bringing the specs here...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic