You are building a web application that will be used throughout the European Union; therefore, it has significant internationalization requirements. You have been tasked to create a custom tag that generates a message using the java.text.MessageFormat class. The tag will take the resourceKey attribute and a variable number of argument attributes with the format, arg
generates:
The disk "MyDisk" contains 1247 file(s).
Which Simple tag class definition accomplishes this goal of handling a variable number of tag attributes?
A. public class MessageTag extends SimpleTagSupportimplements VariableAttributes {private Map attributes = new HashMap();public void setVariableAttribute(String uri,String name, Object value) {this.attributes.put(name, value);}// more tag handler methods}
B. The Simple tag model does NOT support a variable number of attributes.
C. public class MessageTag extends SimpleTagSupportimplements DynamicAttributes {private Map attributes = new HashMap();public void putAttribute(String name, Object value) {this.attributes.put (name, value);}// more tag handler methods}
D. public class MessageTag extends SimpleTagSupportimplements VariableAttributes {private Map attributes = new HashMap();public void putAttribute(String name, Object value) {this.attributes.put (name, value);}// more tag handler methods}
E. public class MessageTag extends SimpleTagSupportimplements DynamicAttributes {private Map attributes = new HashMap();public void setDynamicAttribute(String uri, String name,Object value) {this.attributes.put(name, value);}// more tag handler methods}
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.
43.
44.
45.
jdbc:pointbase:server://dbhost:4747/prefsDB
46.
47.
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}
Which three are true about the HttpServletRequestWrapper class? (Choose three.)
A. The HttpServletRequestWrapper is an example of the Decorator pattern.
B. The HttpServletRequestWrapper can be used to extend the functionality of a servlet request.
C. A subclass of HttpServletRequestWrapper CANNOT modify the behavior of the getReader method.
D. An HttpServletRequestWrapper may be used only by a class implementing the javax.servlet.Filter interface.
E. An HttpServletRequestWrapper CANNOT be used on the request passed to the RequestDispatcher.include method.
F. An HttpServletRequestWrapper may modify the header of a request within an object implementing the javax.servlet.Filter interface.
Which method must be used to encode a URL passed as an argument to HttpServletResponse.sendRedirect when using URL rewriting for session tracking?
A. ServletResponse.encodeURL
B. HttpServletResponse.encodeURL
C. ServletResponse.encodeRedirectURL
D. HttpServletResponse.encodeRedirectURL
Your web application views all have the same header, which includes the
10.
Which JSP code snippet should you use in your main view JSPs to insert the header and pass the pageTitle variable?
A.
B.
C.
D.
E.
Your web application uses a simple architecture in which servlets handle requests and then forward to a JSP using a request dispatcher. You need to pass information calculated in the servlet to the JSP for view generation. This information must NOT be accessible to any other servlet, JSP or session in the webapp. Which two techniques can you use to accomplish this goal? (Choose two.)
A. Add attributes to the session object.
B. Add attributes on the request object.
C. Add parameters to the request object.
D. Use the pageContext object to add request attributes.
E. Add parameters to the JSP's URL when generating the request dispatcher.
Which path is required to be present within a WAR file?
A. /classes
B. /index.html
C. /MANIFEST-INF
D. /WEB-INF/web.xml
E. /WEB-INF/classes
F. /WEB-INF/index.html
G. /META-INF/index.xml
As a convenience feature, your web pages include an Ajax request every five minutes to a special servlet that monitors the age of the user's session. The client-side JavaScript that handles the Ajax callback displays a message on the screen as the session ages. The Ajax call does NOT pass any cookies, but it passes the session ID in a request parameter called sessionID. In addition, assume that your webapp keeps a hashmap of session objects by the ID. Here is a partial implementation of this servlet:
10.
public class SessionAgeServlet extends HttpServlet {
11.
public void service(HttpServletRequest request, HttpServletResponse) throws IOException {
12.
String sessionID = request.getParameter("sessionID");
13.
HttpSession session = getSession(sessionID);
14.
long age = // your code here
15.
response.getWriter().print(age);
16.
}
... // more code here
47. }
Which code snippet on line 14, will determine the age of the session?
A. session.getMaxInactiveInterval();
B. session.getLastAccessed().getTime() - session.getCreationTime().getTime();
C. session.getLastAccessedTime().getTime() - session.getCreationTime().getTime();
D. session.getLastAccessed() - session.getCreationTime();
E. session.getMaxInactiveInterval() - session.getCreationTime();
F. session.getLastAccessedTime() - session.getCreationTime();
Given a portion of a valid Java EE web application's directory structure:
MyApp | |-- File1.html | |-- Directory1 | |-- File2.html | |-- META-INF |-- File3.html You want to know whether File1.html, File2.html, and/or File3.html will be directly accessible by your web client's browsers.
Which statement is true?
A. All three files are directly accessible.
B. Only File1.html is directly accessible.
C. Only File2.html is directly accessible.
D. Only File3.html is directly accessible.
E. Only File1.html and File2.html are directly accessible.
F. Only File1.html and File3.html are directly accessible.
G. Only File2.html and File3.html are directly accessible.
Which method must be used to encode a URL passed as an argument to HttpServletResponse.sendRedirect when using URL rewriting for session tracking?
A. ServletResponse.encodeURL
B. HttpServletResponse.encodeURL
C. ServletResponse.encodeRedirectURL
D. HttpServletResponse.encodeRedirectURL