aspose file tools*
The moose likes Servlets and the fly likes Test 498 question relating to jsp:useBean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Test 498 question relating to jsp:useBean" Watch "Test 498 question relating to jsp:useBean" New topic
Author

Test 498 question relating to jsp:useBean

SAFROLE YUTANI
Ranch Hand

Joined: Jul 06, 2001
Posts: 257
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

Joined: May 10, 2000
Posts: 1913
    
    6
Here's a hint ... the default scope is "page".
Does that help?
Cheers
Simon
SAFROLE YUTANI
Ranch Hand

Joined: Jul 06, 2001
Posts: 257
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

Joined: May 10, 2000
Posts: 1913
    
    6
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

Joined: Jul 06, 2001
Posts: 257
Yes. Thank you. I just tested this on Weblogic to see it in action, and it worked.
Thanks again Simon,
SAF
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Test 498 question relating to jsp:useBean