• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jsp:useBean tag question in mock exam

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic