Skip to Main Content
Head First Servlets and JSP, 2nd Edition
book

Head First Servlets and JSP, 2nd Edition

by Bryan Basham, Kathy Sierra, Bert Bates
March 2008
Intermediate to advanced content levelIntermediate to advanced
911 pages
20h 31m
English
O'Reilly Media, Inc.
Content preview from Head First Servlets and JSP, 2nd Edition

Coffee Cram: Chapter 6 Answers

  1. Given:

    (Servlet Spec p. 59)

    10. public class MyServlet extends HttpServlet {
    11.   public void doGet(HttpServletRequest request,
                              HttpServletResponse response)
    12.           throws IOException, ServletException {
    13.   // request.getSession().setAttribute("key", "value");
    14.   // request.getHttpSession().setAttribute("key", "value");
    15.   // ((HttpSession)request.getSession()).setAttribute("key", "value");
    16.   // ((HttpSession)request.getHttpSession()).setAttribute("key", "value");
    17.   }
    18. }

    Which line(s) could be uncommented without causing a compile or runtime error? (Choose all that apply.)

    A.

    Line 13 only.

    B.

    Line 14 only.

    C.

    Line 15 only.

    D.

    Line 16 only.

    E.

    Line 13 or line 15.

    F.

    Line 14 or line 16.

    Note

    -Option E is correct because both lines 13 and 15 make the correct method call. The cast to HttpSession is NOT necessary, but it does reflect the correct type, so it is valid.

  2. If a client ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The Well-Grounded Java Developer, Second Edition

The Well-Grounded Java Developer, Second Edition

Benjamin Evans, Martijn Verburg, Jason Clark
Learning Java, 4th Edition

Learning Java, 4th Edition

Patrick Niemeyer, Daniel Leuck

Publisher Resources

ISBN: 9780596516680Errata PageSupplemental Content