File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

standard actions.

 
Janhavi Namshikar
Ranch Hand
Posts: 85
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 :

<jsp:useBean id="myobj" type="mypackage.MyClass" scope="session" />

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?

Thanks,
Janhavi.
 
Manish Agarwal
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Janhavi,

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,
Manish
 
Janhavi Namshikar
Ranch Hand
Posts: 85
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Manish,

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?

Thanks,
Janhavi.
 
Sivasundaram Umapathy
Ranch Hand
Posts: 360
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Janhavi.

You would still get the same exception.

Regards
Siva
 
Janhavi Namshikar
Ranch Hand
Posts: 85
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Siva,

In any JSP where I use the standard action in this way :
<jsp:useBean id="myobj" type="mypackage.MyClass" scope="session" />

I should always ensure that there is an instance - myobj, of type MyClass existing in the session scope. If not, then an Exception is thrown.

Thanks once again to both.

Janhavi.
 
Shivani Chandna
Ranch Hand
Posts: 380
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

<jsp:useBean id="wombat" type="my.WombatType" scope="session" />


Regards,
Shivani.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic