Given that a web application consists of two HttpServlet classes, ServletA and ServletB, and the ServletA.service method:
20.
String key = "com.example.data";
21.
session.setAttribute(key, "Hello");
22.
Object value = session.getAttribute(key);
23.
Assume session is an HttpSession, and is not referenced anywhere else in ServletA.
Which two changes, taken together, ensure that value is equal to "Hello" on line 23? (Choose two.)
A. ensure that the ServletB.service method is synchronized
B. ensure that the ServletA.service method is synchronized
C. ensure that ServletB synchronizes on the session object when setting session attributes
D. enclose lines 21-22 in a synchronized block:synchronized(this) {session.setAttribute(key, "Hello");value = session.getAttribute(key);}
E. enclose lines 21-22 in a synchronized block:synchronized(session) {session.setAttribute(key, "Hello");value = session.getAttribute(key);}
Correct Answer: CE
Question 12:
Which retrieves all cookies sent in a given HttpServletRequest request?
A. request.getCookies()
B. request.getAttributes()
C. request.getSession().getCookies()
D. request.getSession().getAttributes()
Correct Answer: A
Question 13:
Your company has a corporate policy that prohibits storing a customer's credit card number in any corporate database. However, users have complained that they do NOT want to re-enter their credit card number for each transaction. Your management has decided to use client-side cookies to record the user's credit card number for 120 days. Furthermore, they also want to protect this information during transit from the web browser to the web container; so the cookie must only be transmitted over HTTPS. Which code snippet creates the "creditCard" cookie and adds it to the out going response to be stored on the user's web browser?
A. 10. Cookie c = new Cookie("creditCard", usersCard);11. c.setSecure(true);12.
B. setAge(10368000);13. response.addCookie(c);
C. 10. Cookie c = new Cookie("creditCard", usersCard);11. c.setHttps(true);12.
D. setMaxAge(10368000);13. response.setCookie(c);
E. 10. Cookie c = new Cookie("creditCard", usersCard);11. c.setSecure(true);12.
F. setMaxAge(10368000);13. response.addCookie(c);
G. 10. Cookie c = new Cookie("creditCard", usersCard);11. c.setHttps(true);12.
H. setAge(10368000);13. response.addCookie(c);
I. 10. Cookie c = new Cookie("creditCard", usersCard);11. c.setSecure(true);12.
J. setAge(10368000);13. response.setCookie(c);
Correct Answer: C
Question 14:
A web browser need NOT always perform a complete request for a particular page that it suspects might NOT have changed. The HTTP specification provides a mechanism for the browser to retrieve only a partial response from the web server; this response includes information, such as the Last- Modified date but NOT the body of the page. Which HTTP method will the browser use to retrieve such a partial response?
A. GET
B. ASK
C. SEND
D. HEAD
E. TRACE
F. OPTIONS
Correct Answer: D
Question 15:
Which ensures that a JSP response is of type "text/plain"?
A. <%@ page mimeType="text/plain" %>
B. <%@ page contentType="text/plain" %>
C. <%@ page pageEncoding="text/plain" %>
D. <%@ page contentEncoding="text/plain" %>
E. <% response.setEncoding("text/plain"); %>
F. <% response.setMimeType("text/plain"); %>
Correct Answer: B
Question 16:
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.
Correct Answer: BE
Question 17:
All of your JSPs need to have a link that permits users to email the web master. This web application is licensed to many small businesses, each of which have a different email address for the web master. You have decided to use a context parameter that you specify in the deployment descriptor, like this:
In a JSP-centric web application, you need to create a catalog browsing JSP page. The catalog is stored as a List object in the catalog attribute of the webapp's ServletContext object. Which scriptlet code snippet gives you access to the catalog object?
A. <% List catalog = config.getAttribute("catalog"); %>
B. <% List catalog = context.getAttribute("catalog"); %>
C. <% List catalog = application.getAttribute("catalog"); %>
D. <% List catalog = servletContext.getAttribute("catalog"); %>
Correct Answer: C
Question 19:
You are building your own layout mechanism by including dynamic content for the page's header and footer sections. The footer is always static, but the header generates the