Hi, I have just started with standard actions (the SCWCD prep. is going at a leisure pace ) Well, I have a question regarding standard action, <jsp:useBean> and the atributes. If I use the useBean standard action like this :
My understanding : an instance of type MyClass should be there in the session,and it given the local name "myobj" and it will be used in the JSP. Question: If the object is not present in the session, would an instance be created and then set in the session? Or will an Exception be thrown?
"Weekends don't count unless you spend them doing something completely pointless."
When you specify only type attribute (without class attribute) in the <jsp:useBean> action then the object specified by "id" (myobj in your case) must be already present in the scope, if it does not present then it will throw "java.lang.InstantiationException".
So punch line is "If type is used without class attribute then bean must already exist in the scope"
Thanks for the answer. Just one more question... If I have an instance of MyClass present in the session, but its not myobj but it is say.. myobj1 or anything else (but myobj) In that case would an Exception be thrown?
Just a small correction - if object is present but of different type than ClassCastException is raised.
From MZ's notes...
The object should have been present in the session. If so, it is given the local name wombat with WombatType. A ClassCastException may be raised if the object is of the wrong class, and an InstantiationException may be raised if the object is not defined: