This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
2 - <jsp:useBean> + BODY - If you utilize <jsp:setProperty> within <jsp:useBean> as body content, The container will utilize "pageContext.findAttribute() for updating the property value"...I mean, it will update the first attribute that it finds.
3- <jsp:getProperty> - don�t have "scope" attribute and the Container finds in all scopes.
does it make sense??
Please correct me if wrong.
SCJP | SCWCD | SCBCD | SCWSD 5 | SCEA (I) 1.4 | SCEA 5 | IBM SOA 669
I've run a quick example on the 1.4 Reference Implementation (Sun AppServer 8), and I think it helps demystify everything.
So, as you can clearly see, as Narendra said, <jsp:useBean /> has a default scope of page (confirmed in the spec.) and <jsp:getProperty /> and <jsp:setProperty /> search all scopes for the scoped attribute.
However, you should really always use <jsp:useBean /> along with the other getter/setter actions, just in case your container generates a slightly different structure of JSP and relies on <jsp:useBean /> being invoked first. I believe it is unwise not to use <jsp:useBean />.
Aleksander, I can only suggest there is a bug in your container - what brand/version is it, and have you checked their bug tracker? [ April 20, 2006: Message edited by: Charles Lyons ]
Charles Lyons (SCJP 1.4, April 2003; SCJP 5, Dec 2006; SCWCD 1.4b, April 2004)
Author of OCEJWCD Study Companion for Oracle Exam 1Z0-899 (ISBN 0955160340 / AmazonAmazon UK )
Joined: Nov 11, 2005
Charles you are always on time I was astonished to find out this behaviour, because spec says <jspProperty> and <jsp:getProperty> will refer to an object through pageContext and it's findAttribute() method. Thank you for clearing all the doubts. We need this for the exam and in fact for our future work.
your expreiment doesnot prove that something is wrong with tomcat.
even though u used following jsp:usebean
still jsp:getProperty ...
will search for the person bean in all scopes starting from pagescope, and thus will find the bean present in the request. this is not the recomended behaviour as far as jsp 2.1 spec is conscerned, but neither is it disallowed by specs. hence nothing is wrong with tomcat.
also i want to quote a para from jsp 2.1 spec titled JSP.5.3 <jsp:getProperty>
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:set- Property and jsp:getProperty actions in that page unless a jsp:useBean action, or some other action, makes them visible. If the JSP processor can ascertain that there is an alternate way guaranteed to access the same object, it can use that information. For example it may use a scripting variable, but it must guarantee that no intervening code has invalidated the copy held by the scripting variable. The truth is always the value held by the pageContext object.
[ April 22, 2006: Message edited by: Jigar Gosar ]