This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes standard actions. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "standard actions." Watch "standard actions." New topic

standard actions.

Janhavi Namshikar
Ranch Hand

Joined: Sep 29, 2005
Posts: 85

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?


"Weekends don't count unless you spend them doing something completely pointless."
Manish Agarwal

Joined: Jan 30, 2006
Posts: 20
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"


SCWCD1.4, SCJP1.4, OCA 9i
Janhavi Namshikar
Ranch Hand

Joined: Sep 29, 2005
Posts: 85

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?

Sivasundaram Umapathy
Ranch Hand

Joined: Aug 10, 2002
Posts: 360
Hi Janhavi.

You would still get the same exception.


Co-Author - SCMAD Exam Guide - ISBN:9780070077881
Author - Java certification success, Part 4: SCEA
Janhavi Namshikar
Ranch Hand

Joined: Sep 29, 2005
Posts: 85

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.

Shivani Chandna
Ranch Hand

Joined: Sep 18, 2004
Posts: 380
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" />


/** Code speaks louder than words */
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: standard actions.
It's not a secret anymore!