Which partial listener class can 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 Java
SE’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 stores the user’s Preference object when an
HTTP session is created. Also, note that user identification information is stored in an HTTP
cookie. Which partial listener class can 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 Java
SE’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 stores the user’s Preference object when an
HTTP session is created. Also, note that user identification information is stored in an HTTP
cookie. Which partial listener class can accomplish this goal?

A.
public class UserPrefLoader implements HttpSessionListener {
public void sessionCreated(HttpSessionEvent se) {
MyPrefsFactory myFactory = (MyPrefsFactory)
se.getServletContext().getAttribute(“myPrefsFactory”);
User user = getUserFromCookie(se);
myFactory.setThreadLocalUser(user);
Preferences userPrefs = myFactory.userRoot();
se.getSession().setAttribute(“prefs”, userPrefs);
}
// more code here
}

B.
public class UserPrefLoader implements SessionListener {
public void sessionCreated(SessionEvent se) {
MyPrefsFactory myFactory = (MyPrefsFactory)
se.getContext().getAttribute(“myPrefsFactory”);
User user = getUserFromCookie(se);
myFactory.setThreadLocalUser(user);
Preferences userPrefs = myFactory.userRoot();
se.getSession().addAttribute(“prefs”, userPrefs);
}
// more code here
}

C.
public class UserPrefLoader implements HttpSessionListener {
public void sessionInitialized(HttpSessionEvent se) {
MyPrefsFactory myFactory = (MyPrefsFactory)
se.getServletContext().getAttribute(“myPrefsFactory”);
User user = getUserFromCookie(se);
myFactory.setThreadLocalUser(user);
Preferences userPrefs = myFactory.userRoot();
se.getHttpSession().setAttribute(“prefs”, userPrefs);
}
// more code here
}

D.
public class UserPrefLoader implements SessionListener {
public void sessionInitialized(SessionEvent se) {
MyPrefsFactory myFactory = (MyPrefsFactory)
se.getServletContext().getAttribute(“myPrefsFactory”);
User user = getUserFromCookie(se);
myFactory.setThreadLocalUser(user);
Preferences userPrefs = myFactory.userRoot();
se.getSession().addAttribute(“prefs”, userPrefs);
}
// more code here
}

Explanation:



Leave a Reply 0

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