Coffee Cram: Chapter 7 Answers

  1. Given this DD element:

    (JSP v2.0 pg 1-87)

    47. <jsp-property-group>
    48.   <url-pattern>*.jsp</url-pattern>
    49.   <el-ignored>true</el-ignored>
    50. </jsp-property-group>

    What does the element accomplish? (Choose all that apply.)

    A.

    All files with the specified extension mapping should be treated by the JSP container as well-formed XML files.

    B.

    All files with the specified extension mapping should have any Expression Language code evaluated by the JSP container.

    C.

    By default, all files with the specified extension mapping should NOT have any Expression Language code evaluated by the JSP container.

    D.

    Nothing, this tag is NOT understood by the container.

    E.

    Although this tag is legal, it is redundant, because the container behaves this way by default.

    Note

    -Option C turns off the evaluating of EL expressions by a JSP 2.0 container and by default the container does evaluate EL.

  2. Which directives specify an HTTP response that will be of type “image/svg”? (Choose all that apply.)

    (JSP v2.0 section 1.10.1)

    A.

    <%@ page type="image/svg" %>

    B.

    <%@ page mimeType="image/svg" %>

    C.

    <%@ page language="image/svg" %>

    D.

    <%@ page contentType="image/svg" %>

    E.

    <%@ page pageEncoding="image/svg" %>

    Note

    -Option D is the correct syntax for this directive.

  3. Given this JSP:

    (JSP v2.0 section 1)

    1. <%@ page import="java.util.*" %>
    2. <html><body> The people who like
    3. <%= request.getParameter("hobby") %>
    4. are: <br>
    5. <% ArrayList al = (ArrayList) request.getAttribute("names"); %>
    6. <% Iterator it = al.iterator();
    7.    while (it.hasNext()) { %>
    8.      <%= it.next() %>
    9. <br>
    10. <% } %>
    11. </body></html>

    Which types of code are used in this JSP? (Choose all that apply.)

    A.

    EL

    B.

    directive

    C.

    expression

    D.

    template text

    E.

    scriptlet

    Note

    -There’s no EL in this JSP. There’s a directive on line 1, expressions on lines 3 and 8, template text all over (like line 2), and of course scripting elements.

  4. Which statements about jspInit() are true? (Choose all that apply.)

    (JSP v2.0 section 11.2.1)

    A.

    It has access to a ServletConfig.

    B.

    It has access to a ServletContext.

    C.

    It is only called once by the Container.

    D.

    It can be overridden.

  5. Which types of objects are available to the jspInit() method? (Choose all that apply.)

    (JSP v2.0 section 11.2.1)

    A.

    ServletConfig

    B.

    ServletContext

    C.

    JspServletConfig

    D.

    JspServletContext

    E.

    HttpServletRequest

    F.

    HttpServletResponse

    Note

    -JSPs turn into plain old servlets, so they have access to the plain old ServletConfig and ServletContext objects... and it’s just a little early in the lifecycle to be talking about requests and responses.

  6. Given:

    <%@ page isELIgnored="true" %>

    What is the effect? (Choose all that apply.)

    (JSP v2.0 pg 1-49)

    A.

    Nothing, this page directive is NOT defined.

    B.

    The directive turns off the evaluation of Expression Language code by the JSP container in all of the web application’s JSPs.

    C.

    The JSP containing this directive should be treated by the JSP container as a well-formed XML file.

    D.

    The JSP containing this directive should NOT have any Expression Language code evaluated by the JSP container.

    E.

    This page directive will only turn off EL evaluation if the DD declares a <el-ignored>true</el-ignored> element with a URL pattern that includes this JSP.

    Note

    -Option B is incorrect because the directive only affects the enclosing JSP.

  7. Which statement concerning JSPs is true? (Choose one.)

    (JSP v2.0 section 11)

    A.

    Only jspInit() can be overridden.

    B.

    Only jspDestroy() can be overridden.

    C.

    Only _jspService() can be overridden.

    D.

    Both jspInit() and jspDestroy() can be overridden.

    E.

    jspInit(), jspDestroy(), and _jspService() can all be overridden.

    Note

    -Remember the underscore is your clue that a method can’t be overridden.

  8. Which JSP lifecycle step is out of order?

    (JSP v2.0 section 11)

    A.

    Translate the JSP into a servlet.

    B.

    Compile servlet source code.

    C.

    Call _jspService()

    D.

    Instantiate the servlet class.

    E.

    Call jspInit()

    F.

    Call jspDestroy()

    Note

    -The _jspService method can never be called before jspInit.

  9. Which are valid JSP implicit variables? (Choose all that apply.)

    (JSP v2.0 section 1.8.3)

    A.

    stream

    B.

    context

    C.

    exception

    D.

    listener

    E.

    application

    Note

    -Options A, B, and D don’t exist as implicit objects created by the container for JSPs.

  10. Given a request with two parameters: one named “first” represents a user’s first name and another named “last” represents his last name.

    Which JSP scriptlet code outputs these parameter values?

    (JSP v2.0 pg 1-41)

    A.

    <% out.println(request.getParameter("first"));
       out.println(request.getParameter("last")); %>

    B.

    <% out.println(application.getInitParameter("first"));
       out.println(application.getInitParameter("last")); %>

    C.

    <% println(request.getParameter("first"));
       println(request.getParameter("last")); %>

    D.

    <% println(application.getInitParameter("first"));
       println(application.getInitParameter("last")); %>

    Note

    -Option A uses the “out” implicit object and its println() method.

    Note

    -Options C and D are missing the “out” implicit object.

  11. Given:

    11. Hello ${user.name}!
    12. Your number is <c:out value="${user.phone}"/>.
    13. Your address is <jsp:getProperty name="user" property="addr" />
    14. <% if (user.isValid()) {%>You are valid!<% } %>

    Which statements are true? (Choose all that apply.)

    (JSP v2.0 pg. 1-10)

    A.

    Lines 11 and 12 (and no others) contain examples of EL elements.

    B.

    Line 14 is an example of scriptlet code.

    C.

    None of the lines in this example contain template text.

    D.

    Lines 12 and 13 include examples of JSP standard actions.

    E.

    Line 11 demonstrates an invalid use of EL.

    F.

    All four lines in this example would be valid in a JSP page.

    Note

    -Option C is incorrect because all four lines include template text.

    Note

    -Option D is incorrect because line 12 does not include a JSP standard action.

    Note

    -Option E is incorrect because the EL in line 11 is valid.

  12. Which JSP expression tag will print the context initialization parameter named “javax.sql.DataSource”?

    (JSP v2.0 pg 1-41)

    A.

    <%= application.getAttribute("javax.sql.DataSource") %>

    B.

    <%= application.getInitParameter("javax.sql.DataSource") %>

    C.

    <%= request.getParameter("javax.sql.DataSource") %>

    D.

    <%= contextParam.get("javax.sql.DataSource") %>

    Note

    -Option B shows the correct use of the application implicit object.

  13. Which statements about disabling scripting elements are true? (Choose all that apply.)

    (JSP v2.0 section 3.3.3)

    A.

    You can’t disable scripting via the DD.

    B.

    You can only disable scripting at the application level.

    C.

    You can disable scripting programmatically by using the isScriptingEnabled page directive attribute.

    D.

    You can disable scripting via the DD by using the <scripting-invalid> element.

    Note

    -You can only disable scripting elements through the DD. The <jsp-property-group> element allows you to disable scripting in selective JSPs by specifying URL patterns to be disabled.

  14. In sequence, what are the Java types of the following JSP implicit objects: application, out, request, response, session?

    (JSP v2.0 pg 1-41)

    A.

    java.lang.Throwable
    java.lang.Object
    java.util.Map
    java.util.Set
    java.util.List

    B.

    javax.servlet.ServletConfig
    java.lang.Throwable
    java.lang.Object
    javax.servlet.jsp.PageContext
    java.util.Map

    C.

    javax.servlet.ServletContext
    javax.servlet.jsp.JspWriter
    javax.servlet.ServletRequest
    javax.servlet.ServletResponse
    javax.servlet.http.HttpSession

    D.

    javax.servlet.ServletContext
    java.io.PrintWriter
    javax.servlet.ServletConfig
    java.lang.Exception
    javax.servlet.RequestDispatcher

    Note

    -Option C shows the Java type of each implicit object.

  15. Which is an example of the syntax used to import a class in a JSP?

    (JSP v2.0 pg. 1-44)

    A.

    <% page import="java.util.Date" %>

    B.

    <%@ page import="java.util.Date" @%>

    C.

    <%@ page import="java.util.Date" %>

    D.

    <% import java.util.Date; %>

    E.

    <%@ import file="java.util.Date" %>

    Note

    -Options A & D are invalid because only Java statements may be included within <% ... %> tags.

    Note

    -Option C is the only example that shows the correct syntax.

    Note

    -Option E is invalid because there is no import directive.

  16. Given the JSP:

    1. <%@ page isELIgnored="true" %>
    2. <%@ taglib uri="http://java.sun.com/jsp/jstl/core"
    prefix="c" %>
    3. <c:set var="awesomeBand" value="LIMOZEEN"/>
    4. ${awesomeBand}

    What will be the output?

    (JSP v2.0 section 1.10.1)

    A.

    ${awesomeBand}

    B.

    LIMOZEEN

    C.

    No output

    D.

    An exception will be thrown because all taglib directives must precede any page directives.

    Note

    -Option A the EL expression is ignored and passed through verbatim.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset