wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes jsp:useBean type attribute problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "jsp:useBean type attribute problem" Watch "jsp:useBean type attribute problem" New topic
Author

jsp:useBean type attribute problem

Rick Rangers
Ranch Hand

Joined: Feb 06, 2007
Posts: 47
Hi,

I'm doing a test exam in preparation for my real exam next week
and given the following snippet:

<jsp:useBean id="cust" type="test.beans.CustomerBean" scope="session" />

The explanation of the question says that a CustomerBean instance is created if the attribute name cust is not found.

My book (Deshmukh) says that if you only specify a type and an object
cannot be located an InstantiatonException will occur. Which one
is correct? Deshmukh makes more sence to me because if the type would be an interface then you can't instantiate an object, right?


SCJP 5.0<br />SCWCD 1.4<br />IBM Certified Associate Developer -- Rational Application Developer for WebSphere Software V6.0<br />IBM Certified Solution Developer - IBM WebSphere Portal V6.0
Chaminda Amarasinghe
Ranch Hand

Joined: May 17, 2006
Posts: 402
Yes,

you are correct. if useBean with type attribute the object (which set to id att.) must be in the specified scope.

useBean with class att. creats a new object if that is not in the scope.

You can test this by writng simple code.
Chaminda Amarasinghe
Ranch Hand

Joined: May 17, 2006
Posts: 402
sorry,

i made a mistake, the scope specifies where we create the new object..

but now i have a question,

what is the usefullness of scope att. with type att. (without class att.)? because we cant create new object. so i think that is meaningless only type and scope atts.

can other make clear this?
Rick Rangers
Ranch Hand

Joined: Feb 06, 2007
Posts: 47
If you use both the type attribute and scope attribute you specify
in which scope the bean referenced by a variable of type "type" should
be searched.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp:useBean type attribute problem
 
Similar Threads
jsp:useBean tag question in mock exam
mistake in assesment exam?
question of useBean
get fresh data from database using HttpSessionListener
Bad answer in question in Sun preparation exam