Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Test 498 question relating to jsp:useBean

 
SAFROLE YUTANI
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cant figure out this answer. I know a) and b) are not correct because there is no such scope as "config" and "context. Anyway, here is the question.

A Web application on startup reads global information from the database into com.ibm.ApplicationInfo JavaBean and adds the bean to the servlet context. Which of the following tags allow accessing this information from a JSP page?
a) jsp:useBean id="appInfo" class="com.ibm.ApplicationInfo" scope="config"
b) jsp:useBean id="appInfo" class="com.ibm.ApplicationInfo" scope="context"
c) jsp:useBean id="appInfo" class="com.ibm.ApplicationInfo"
d) jsp:useBean id="appInfo" class="com.ibm.ApplicationInfo" scope="application"
SAF
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a hint ... the default scope is "page".
Does that help?
Cheers
Simon
 
SAFROLE YUTANI
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's exactly the info I was looking for because I knew that for option c) there is no scope specified, therefore, I knew a default was being used, but I wasn't sure what it was.
c) is therefore the answer.
Thanks man,
SAF
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The jsp:useBean action looks for a named instance in the specified scope and if it is isn't there, it creates it. This means that answer (c) will try to find a bean called appInfo on the page.
However, the startup process initialises the JavaBean and binds this into the servlet context. This is (if you like) a global area for the whole of your application, and is therefore accessed by using the "application" scope.
Although answer (c) will compile and run, it will in fact create a new instance rather than finding the instance that has already been configured and bound to the servlet context.
In short, answer (d) is correct.
[This message has been edited by Simon Brown (edited August 23, 2001).]
 
SAFROLE YUTANI
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Thank you. I just tested this on Weblogic to see it in action, and it worked.
Thanks again Simon,
SAF
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic