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:
42. <context-param>
43. <param-name>prefsDbURL</param-name>
44. <param-value>
45. jdbc:pointbase:server://dbhost:4747/prefsDB
46. </param-value>
47. </context-param>
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:
42. <context-param>
43. <param-name>prefsDbURL</param-name>
44. <param-value>
45. jdbc:pointbase:server://dbhost:4747/prefsDB
46. </param-value>
47. </context-param>
Which partial listener class will accomplish this goal?

A.
public class PrefsFactoryInitializer implements ContextListener {
public void contextInitialized(ServletContextEvent e) {
ServletContext ctx = e.getContext();
String prefsURL = ctx.getParameter(“prefsDbURL”);
PreferencesFactory myFactory = makeFactory(prefsURL);
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(“myPrefsFactory”, myFactory);
}
// more code here
}

C.
public class PrefsFactoryInitializer implements ServletContextListener {
public void contextInitialized(ServletContextEvent e) {
ServletContext ctx = e.getServletContext();
String prefsURL = ctx.getInitParameter(“prefsDbURL”);
PreferencesFactory myFactory = makeFactory(prefsURL);
ctx.setAttribute(“myPrefsFactory”, 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(“myPrefsFactory”, myFactory);
}
// more code here
}

Explanation:



Leave a Reply 0

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