This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
(For options E and F, ignore the fact that an error in one line might keep a subsequent line from being reached)
A. Only line 2 will definitely generate an error B. Only line 3 will definitely generate an error C. Only line 4 will definitely generate an error D. Only line 5 will definitely generate an error E. Lines 4 and 5 will both definitely generate errors F. Lines 2, 3, 4 and 5 will all definitely generate errors G. The entire JSP could execute without generating any errors
Handwritten notes: - Options A and B are incorrect because, assuming the tags used are appropriately defined in the mytags tag library, there is nothing wrong with them
- Option C is incorrect because this is a valid JSP standard action. The jsp prefix does not need to be referenced in a taglib directive
- Option D is correct because there is no taglib directive shown for the prefix c.
As I understand it, <jsp:useBean> creates a local variable in the _jspService() method with the name as specified in the 'id' attribute. So, as I see it, the <jsp:setProperty> in this code should also cause an exception because there is no <jsp:useBean> action anywhere.
Am I missing something here or is this actually wrong? [ October 08, 2007: Message edited by: Tarun Yadav ]
In my opinion, there first should be bean instantiated, for example bij using "jsp:useBean".
Yes, you are right, a bean should be instantiated (however not necessarily by a jsp:useBean action). The answer to the question is wrong!
David Bridgewater in his book states:
1. The setProperty/getProperty can be used on a bean not defined in a <jsp:useBean>. If the bean is available in the page scope. (but if it isn't there it will result in an error 500) However it is not recommended to do so.
And the JSP2.0 specs say:
JSP.5.2 <jsp:setProperty> name The name of a bean instance defined by a <jsp:useBean> action or some other action. The bean instance must contain the property to be set. The defining action must appear before the <jsp:setProperty> action in the same file.
Joined: Feb 06, 2011
Thanks for your reply. It gets sometimes confusing, sorting out the answers.
I find Javaranch often to the rescue, a good place to look for brothers-in-arms,
just like now, where somebody else, a couple of years ago, struggled the same issue.
Or to find friendly advice from a rancher.