Coffee Cram: Mock Exam Chapter 8

  1. Given an HTML form that uses checkboxes to allow a user to select multiple values for a parameter called hobbies.

    Which EL expressions evaluate to the first value of the hobbies parameter? (Choose all that apply.)

    A.

    ${param.hobbies}

    B.

    ${paramValue.hobbies}

    C.

    ${paramValues.hobbies[0]}

    D.

    ${paramValues.hobbies[1]}

    E.

    ${paramValues[hobbies][0]}

    F.

    ${paramValues[hobbies][1]}

  2. Given that a web application stores the webmaster email address in the servlet context initialization parameter called master-email.

    Which retrieves that value? (Choose all that apply.)

    A.

    <a href='mailto:${initParam.master-email}'>
        email me</a>

    B.

    <a href='mailto:${contextParam.master-email}'>
        email me</a>

    C.

    <a href='mailto:${initParam['master-email']}'>
        email me</a>

    D.

    <a href='mailto:${contextParam['master-email']}'>
        email me</a>
  3. Given the following Java class:

    1. package com.mycompany;
    2. public class MyFunctions {
    3.   public static String hello(String name) {
    4.     return "Hello "+name;
    5.   }
    6. }

    This class represents the handler for a function that is part of a tag library. <%@ taglib uri="http://mycompany.com.tags" prefix="comp" %> Which Tag Library Descriptor entry defines this custom function so that it can be used in an EL expression?

    A.

    <taglib>
      ...
      <tag>
        <name>Hello</name>
        <tag-class>com.mycompany.MyFunctions</tag-class>
        <body-content>JSP</body-content>
      </tag>
    </taglib>

    B.

    <taglib>
     ...
      <function>
        <name>Hello</name>
        <function-class>com.mycompany.MyFunctions</function-class>
        <function-signature>java.lang.String hello(java.lang.String)
             </function-signature>
      </function>
    </taglib>

    C.

    <web-app>
      ...
      <servlet>
        <servlet-name>hello</servlet-name>
        <servlet-class>com.mycompany.MyFunctions</servlet-class>
      </servlet>
    </web-app>

    D.

    <taglib>
      ...
      <function>
        <name>Hello</name>
        <function-class>com.mycompany.MyFunctions</function-class>
        <function-signature>hello(java.lang.String)</function-signature>
      </function>
    </taglib>
  4. Given:

    1. package com.example;
    2. public class TheBean {
    3.    private int value;
    4.    public TheBean() { value = 42; }
    5.    public int getValue() { return value; }
    6.    public void setValue(int v) { value = v; }
    7. }

    Assuming no instances of TheBean have been created yet, which JSP standard action statements create a new instance of this bean and store it in the request scope? (Choose all that apply.)

    A.

    <jsp:useBean name="myBean"
         type="com.example.TheBean" />

    B.

    <jsp:makeBean name="myBean"
         type="com.example.TheBean" />

    C.

    <jsp:useBean id="myBean"
         class="com.example.TheBean"
         scope="request" />

    D.

    <jsp:makeBean id="myBean"
         class="com.example.TheBean"
         scope="request" />
  5. Given a Model 1 architecture in which a JSP page handles all of the controller functions, that JSP controller needs to dispatch the request to another JSP page.

    Which standard action code will perform this dispatch?

    A.

    <jsp:forward page="view.jsp" />

    B.

    <jsp:forward file="view.jsp" />

    C.

    <jsp:dispatch page="view.jsp" />

    D.

    <jsp:dispatch file="view.jsp" />

  6. Given:

    11. <% java.util.List list = new java.util.ArrayList();
    12.    list.add("a");
    13.    list.add("2");
    14.    list.add("c");
    15.    request.setAttribute("list", list);
    16.    request.setAttribute("listIdx", "1");
    17. %>
    18. <%-- insert code here --%>

    Which, inserted at line 18, are valid and evaluate to c ? (Choose all that apply.)

    A.

    ${list.2}

    B.

    ${list[2]}

    C.

    ${list.listIdx+1}

    D.

    ${list[listIdx+1]}

    E.

    ${list['listIdx' + 1]}

    F.

    ${list[list[listIdx]]}

  7. Which statements about the . (dot) and [] EL operators are true? (Choose all that apply.)

    A.

    ${foo.bar} is equivalent to ${foo[bar]}

    B.

    ${foo.bar} is equivalent to ${foo["bar"]}

    C.

    ${foo["5"]} is valid syntax if foo is a Map

    D.

    ${header.User-Agent} is equivalent to ${header[User-Agent]}

    E.

    ${header.User-Agent} is equivalent to ${header["User-Agent"]}

    F.

    ${foo[5]} is valid syntax if foo is a List or an array

  8. Given a JSP page with the line:

    ${101 % 10}

    What will be displayed?

    A.

    1

    B.

    10

    C.

    1001

    D.

    101 % 10

    E.

    {101 % 10}

  9. Given:

    10. ${param.firstname}
    11. ${param.middlename}
    12. ${param.lastname}
    13. ${paramValues.lastname[0]}

    Which describes the output produced by this portion of a JSP page when passed the query string ?firstname=John&lastname=Doe?

    A.

    John Doe

    B.

    John Doe Doe

    C.

    John null Doe

    D.

    John null Doe Doe

    E.

    A null pointer exception will be thrown.

  10. Which show valid usage of EL implicit variables? (Choose all that apply.)

    A.

    ${cookies.foo}

    B.

    ${initParam.foo}

    C.

    ${pageContext.foo}

    D.

    ${requestScope.foo}

    E.

    ${header["User-Agent"]}

    F.

    ${requestDispatcher.foo}

    G.

    ${pageContext.request.requestURI}

  11. Which are true about the <jsp:useBean> standard action? (Choose all that apply.)

    A.

    The id attribute is optional.

    B.

    The scope attribute is required.

    C.

    The scope attribute is optional and defaults to request.

    D.

    Either the class or type attributes may be specified, but at least one.

    E.

    It is valid to include both the class attribute and the type attribute, even if their values are NOT the same.

  12. How would you include dynamic content in a JSP, similar to a server-side include (SSI)? (Choose all that apply.)

    A.

    <%@ include file="/segments/footer.jspf" %>

    B.

    <jsp:forward page="/segments/footer.jspf" />

    C.

    <jsp:include page="/segments/footer.jspf" />

    D.

    RequestDispatcher dispatcher
      = request.getRequestDispatcher("/segments/footer.jspf");
    dispatcher.include(request,response);
  13. In an HTML page with a rich, graphical layout, which JSP standard action can be used to import an image file into the JSP page?

    A.

    <jsp:image page="logo.png" />

    B.

    <jsp:image file="logo.png" />

    C.

    <jsp:include page="logo.png" />

    D.

    <jsp:include file="logo.png" />

    E.

    This CANNOT be done using a JSP standard action.

  14. Given:

    1. package com.example;
    2. public class MyFunctions {
    3.   public static String repeat(int x, String str) {
    4.      // method body
    5.   }
    6. }

    and given the JSP:

    1. <%@ taglib uri="/WEB-INF/myfuncts" prefix="my" %>
    2. <%-- insert code here --%>

    Which, inserted at line 2 in the JSP, is a valid EL function invocation?

    A.

    ${repeat(2, "420")}

    B.

    ${repeat("2", "420")}

    C.

    ${my:repeat(2, "420")}

    D.

    ${my:repeat("2", "420")}

    E.

    A valid invocation CANNOT be determined.

  15. Given:

    10. public class MyBean {
    11.   private java.util.Map params;
    12.   private java.util.List objects;
    13.   private String name;
    14.   public java.util.Map getParams() { return params; }
    15.   public String getName() { return name; }
    16.   public java.util.List getObjects() { return objects; }
    17. }

    Which will cause errors (assume that an attribute named mybean can be found, and is of type MyBean)? (Choose all that apply.)

    A.

    ${mybean.name}

    B.

    ${mybean["name"]}

    C.

    ${mybean.objects.a}

    D.

    ${mybean["params"].a}

    E.

    ${mybean.params["a"]}

    F.

    ${mybean["objects"].a}

  16. Given a JSP page:

    1. The user has sufficiently logged in or out:
    2.   ${param.loggedIn or param.loggedOut}.

    If the request includes the query string “loggedOut=true", what will be this statement’s displayed value?

    A.

    The user has sufficiently logged in or out: false.

    B.

    The user has sufficiently logged in or out: true.

    C.

    The user has sufficiently logged in or out: ${param. loggedIn or param.loggedOut}.

    D.

    The user has sufficiently logged in or out: param. loggedIn or param.loggedOut.

    E.

    The user has sufficiently logged in or out: or true.

  17. Which about EL access operators are true? (Choose all that apply.)

    A.

    Anywhere the . (dot) operator is used, the [] could be used instead.

    B.

    Anywhere the [] operator is used, the . (dot)could be used instead.

    C.

    If the . (dot) operator is used to access a bean property but the property doesn’t exist, then a runtime exception is thrown.

    D.

    There are some situations where the . (dot)operator must be used and other situations where the [] operator must be used.

  18. The following code fragment appears in a JSP page:

    <jsp:include page="/jspf/header.html"/>

    The JSP page is part of a web application with the context root myapp.

    Given that the application’s top level directory is myapp, what is the path to the header.html file?

    A.

    /header.html

    B.

    /jspf/header.html

    C.

    /myapp/jspf/header.html

    D.

    /includes/jspf/header.html

  19. An online jewelry retailer wishes to customize their online catalog for users who are logged in. They want to show specials for the user’s birthstone month. The company’s special offers are stored as a Map<String, Special[]> identified as specials in application scope and updated daily.

    There is a bean stored as a session-scoped attribute named userInfo. Calling getBirthdate().getMonth() on this bean will return the user’s birthstone month.

    Which of the following code snippets could correctly retrieve the appropriate special offerings?

    A.

    ${applicationScope[userInfo.birthdate.month.specials]}

    B.

    ${applicationScope.specials[userInfo.birthdate.month]}

    C.

    ${applicationScope["specials"].userInfo.birthdate.month}

    D.

    ${applicationScope["userInfo.birthdate.month"].specials}

  20. A web based application for a major online movie rental retailer stores a List<Movie> as a session attribute to contain movies the user has requested. A random, embedded movie trailer from this list must display on the users’ main page every time the users’ main page is viewed.

    Management thinks a similar feature will be needed in the near future on other pages that display lists of movies. Streaming video is accomplished with regular HTML, just like adding images to a page but with more complex tags.

    The development team needs a solution that is both flexible and maintainable. One possible solution is to create an EL function. The following statements are from a team meeting concerning EL functions as a solution to this problem. Which statements are true? (Choose all that apply.)

    A.

    EL functions can not solve this problem because they can not retrieve session attributes.

    B.

    The method implementing the EL function should not be declared static to give it access to session scope.

    C.

    The EL function can accept a parameter of java.util.List which will allow the needed movie list to be passed to it using EL.

    D.

    You might have to write HTML tags in the middle of Java code using an EL function, which is more difficult to maintain.

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

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