Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:useBean tag question in mock exam

 
aanal jethalia
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I came across the following question in the sun epractice exam:

Given a JSP page with the line:
<jsp:useBean id="cust" type="test.beans.CustomerBean" scope="session" />
Which two occur? (Choose two.)

A A CustomerBean instance is created if the attribute name cust is not found.
B The session is searched for a CustomerBean stored as the attribute name cust.
C The CustomerBean instance is populated with the values of the parameters in the request.
D A CustomerBean instance is always created and stored in the session with the attribute name cust.
E The CustomerBean identified by cust is located in the application and then stored in the session for later use.

The correct answers stated are options A and B.

But I am doubtful about option A being correct. If we only use the "type" attribute and if the bean doesnot exist, does the container not throw an InstantiationException?

Please let me know if I this is the case. Thanks
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer should be B alone. If only type is specified, the attribute better exist in the scope specified ( the default being page. ). If it does not exist then a runtime exception is thrown.
 
aanal jethalia
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool....I am happy I was right....I found this question on one of the epractice exams I bought from sun's website...so had doubts about my understanding.....thanks for the confirmation
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, when only the type attribute is used, the thing named by it, must exist in the specified scope. and also, no bean will be created as you are not giving full information to the container i.e

type x = new class();

you are not telling the containr anything about the class,

hth
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic