Which partial listener class will accomplish this goal?

Your web site has many user-customizable features, for example font and color preferences on web pages. Your IT department has already built a subsystem for user preferences using the Java SE platform’s lang.util.prefs package APIs, and you have been ordered to reuse this subsystem in your web application. You need to create an event listener that constructs the preferences factory and stores it in the application scope for later use.
Furthermore, this factory requires that the URL to a database must be declared in the deployment descriptor like this:
<context-param>
<param-name>prefsDbURL</param-name>
<param-value>jdbc:pointbase:server://dbhost:4747/prefsDB</param-value>
</context-param>
Which partial listener class will accomplish this goal?
A. public class PrefsFactoryInitializer implements ContextListener {
public void contextInitialized (ServletContextEvent e) {
ServletContect ctx = e.getParameter("prefsDbURL");
ctx.putAttribute("myPrefsFactory", myFactory);
}
//more code here
}
B. public class PrefsFactoryInitializer implements ServletContextListener {
public void contextCreated (ServletContext ctx) {
String prefsURL = ctx.getInitParameter(“prefsDbURL”);
PreferencesFactory myFactory = makeFactory(prefsURL);
ctx.setAttribute(“mePrefsFactory”, myFactory);
}
//more code here
}
C. public class PrefsFactoryInitializer implements ServletContextListener {
public void contextInitialized (ServletContextEvent e) {
ServletContect ctx = e.getServletContext();
String prefsURL = ctx.getInitParameter(“prefsDbURL”);
PreferencesFactory myFactory = makeFactory(prefsURL);
ctx.setAttribute(“mePrefsFactory”, myFactory);
}
//more code here
}
D. public class PrefsFactoryInitializer implements ContextListener {
public void contextCreated (ServletContext ctx) {
String prefsURL = ctx.getParameter(“prefsDbURL”);
PreferencesFactory myFactory = makeFactory(prefsURL);
ctx.putAttribute(“mePrefsFactory”, myFactory);
}
//more code here
}

Download Printable PDF. VALID exam to help you PASS.

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.