Coffee Cram: Mock Exam Chapter 10

  1. How can a Classic tag handler instruct the container to ignore the remainder of the JSP that invoked the tag?

    (Choose all that apply.)

    A.

    The doEndTag() method should return Tag.SKIP_BODY.

    B.

    The doEndTag() method should return Tag.SKIP_PAGE.

    C.

    The doStartTag() method should return Tag.SKIP_BODY.

    D.

    The doStartTag() method should return Tag.SKIP_PAGE.

  2. Which directives and/or standard actions are applicable ONLY within tag files? (Choose all that apply.)

    A.

    tag

    B.

    page

    C.

    jsp:body

    D.

    jsp:doBody

    E.

    taglib

  3. A medical website hides selective content from users who are not registered. In place of the hidden content, a message should display to encourage users to register. Given the Simple tag handler snippet:

    11. public void doTag() throws JspException, IOException {
    12.    String level =
    13.      (String) getJspContext().findAttribute("accountLevel");
    14.    if((level == null || "trial".equals(level))) {
    15.      String price = "?"; // TODO get context param
    16.      String message = "Content for paying members
                                 only.<br/>"+
    17.        "<a href="register.jsp">Sign up now for only
                                 "+price+"!</a>";
    18.      getJspContext().getOut().write(message);
    19.    } else {
    20.      getJspBody().invoke(null);
    21.    }
    22. }

    At line 15, the price for registration should be retrieved from a context parameter named registrationFee, however there are no methods on JspContext for retrieving context parameters. What can solve this problem?

    A.

    Retrieve the value with pageContext.getServletContext() .getInitParameter("registrationFee");

    B.

    Cast the JspContext to type PageContext so that you can use the methods of PageContext to retrieve the context parameter.

    C.

    Retrieve the value with getJspContext().findAttribute("registrationFee");

    D.

    Throw an exception to let the user know that the price could not be found.

    E.

    This is impossible with a Simple tag. A Classic tag must be used.

  4. Which Simple tag mechanism will tell a JSP page to stop processing?

    A.

    Return SKIP_PAGE from the doTag method.

    B.

    Return SKIP_PAGE from the doEndTag method.

    C.

    Throw a SkipPageException from the doTag method.

    D.

    Throw a SkipPageException from the doEndTag method.

  5. Which are true about the Classic tag model? (Choose all that apply.)

    A.

    The Tag interface can only be used to create empty tags.

    B.

    The SKIP_PAGE constant is a valid return value of the doEndTag method.

    C.

    The EVAL_BODY_BUFFERED constant is a valid return value of the doAfterBody method.

    D.

    The Tag interface only provides two values for the return value of the doStartTag method: SKIP_BODY and EVAL_BODY.

    E.

    There are three tag interfaces—Tag, IterationTag, and BodyTag—but only two built-in base classes: TagSupport, and BodyTagSupport.

  6. Which must be true if you want to use dynamic attributes for a Simple tag handler? (Choose all that apply.)

    A.

    Your Simple tag must NOT declare any static tag attributes.

    B.

    Your Simple tag must use the <dynamic-attributes> element in the TLD.

    C.

    Your Simple tag handler must implement the DynamicAttributes interface.

    D.

    Your Simple tag should extend the DynamicSimpleTagSupport class, which provides default support for dynamic attributes.

    E.

    Your Simple tag CANNOT be used with the jsp:attribute standard action, because this action works only with static attributes.

  7. Which is true about tag files? (Choose all that apply.)

    A.

    A tag file may be placed in any subdirectory of WEB-INF.

    B.

    A tag file must have the file extension of .tag or .tagx.

    C.

    A TLD file must be used to map the symbolic tag name to the actual tag file.

    D.

    A tag file may NOT be placed in a JAR file in the WEB-INF/lib directory.

  8. Given:

    10. public class BufTag extends BodyTagSupport {
    11.   public int doStartTag() throws JspException {
    12.     // insert code here
    13.   }
    14. }

    Assume that the tag has been properly configured to allow body content.

    Which, if inserted at line 12, would cause the JSP code <mytags:mytag>BodyContent</mytags:mytag> to output BodyContent?

    A.

    return SKIP_BODY;

    B.

    return EVAL_BODY_INCLUDE;

    C.

    return EVAL_BODY_BUFFERED;

    D.

    return BODY_CONTENT;

  9. Which about doAfterBody() is true? (Choose all that apply.)

    A.

    doAfterBody() is only called on tags that extend TagSupport.

    B.

    doAfterBody() is only called on tags that extend IterationTagSupport.

    C.

    Assuming no exceptions occur, doAfterBody() is always called after doStartTag() for any tag that implements IterationTag.

    D.

    Assuming no exceptions occur, doAfterBody() is called after doStartTag() for any tag that implements IterationTag and returns SKIP_BODY from doStartTag().

    E.

    Assuming no exceptions occur, doAfterBody() is called after doStartTag() for any tag that implements IterationTag and returns EVAL_BODY_INCLUDE from doStartTag().

  10. Given a JSP page:

    1. <%@ taglib prefix="my" uri="/WEB-INF/myTags.tld" %>
    2. <my:tag1>
    3.    <%-- JSP content --%>
    4. </my:tag1>

    The tag handler for my:tag1 is Tag1Handler and extends TagSupport. What happens when the instance of Tag1Handler calls the getParent method? (Choose all that apply.)

    A.

    A JspException is thrown.

    B.

    The null value is returned.

    C.

    A NullPointerException is thrown.

    D.

    An IllegalStateException is thrown.

  11. Which is true about the lifecycle of a Simple tag? (Choose all that apply.)

    A.

    The release method is called after the doTag method.

    B.

    The setJspBody method is always called before the doTag method.

    C.

    The setParent and setJspContext methods are called immediately before the tag attributes are set.

    D.

    The JspFragment of the tag body is invoked by the Container before the tag handler’s doTag method is called. This value, a BodyContent object, is passed to the tag handler using the setJspBody method.

  12. Given:

    10. public class ExampleTag extends TagSupport {
    11.   private String param;
    12.   public void setParam(String p) { param = p; }
    13.   public int doStartTag() throws JspException {
    14.     // insert code here
    15.     // more code here
    16.   }
    17. }

    Which, inserted at line 14, would be guaranteed to assign the value of the request-scoped attribute param to the local variable p? (Choose all that apply.)

    A.

    String p = findAttribute("param");

    B.

    String p = request.getAttribute("param");

    C.

    String p = pageContext.findAttribute("param");

    D.

    String p = getPageContext().findAttribute("param");

    E.

    String p = (String) pageContext.getRequest().getAttribute("param");

  13. Which are valid method calls on a PageContext object? (Choose all that apply.)

    A.

    getAttributeNames()

    B.

    getAttribute("key")

    C.

    findAttribute("key")

    D.

    getSessionAttribute()

    E.

    findAttribute("key", PageContext.SESSION_SCOPE)

    F.

    getAttribute("key", PageContext.SESSION_SCOPE)

  14. Which is the most efficient JspContext method to call to access an attribute that is known to be in application scope?

    A.

    getPageContext()

    B.

    getAttribute(String)

    C.

    findAttribute(String)

    D.

    getAttribute(String, int)

    E.

    getAttributesScope("key")

    F.

    getAttributeNamesInScope(int)

  15. What is the best strategy, when implementing a custom tag, for finding the value of an attribute whose scope is unknown?

    A.

    Check all scopes with a single pageContext.getAttribute(String) call.

    B.

    Check all scopes with a single pageContext.findAttribute(String) call.

    C.

    Check each scope with calls to pageContext.getAttribute(String, int).

    D.

    Call pageContext.getRequest().getAttribute(String), then call pageContext.getSession().getAttribute(String), and so on.

    E.

    None of these will work.

  16. Given a tag, simpleTag, whose handler is implemented using the Simple tag model and a tag, complexTag, whose handler is implemented using the Classic tag model. Both tags are declared to be non-empty and non-tag dependent in the TLD.

    Which JSP code snippets are valid uses of these tag? (Choose all that apply.)

    A.

    <my:simpleTag>
      <my:complexTag />
    </my:simpleTag>

    B.

    <my:simpleTag>
      <%= displayText %>
    </my:simpleTag>

    C.

    <my:simpleTag>
      <%@ include file="/WEB-INF/web/common/headerMenu.html" %>
    </my:simpleTag>

    D.

    <my:simpleTag>
      <my:complexTag>
        <% i++; %>
      </my:complexTag>
    </my:simpleTag>
  17. Which are true about the Tag File model? (Choose all that apply.)

    A.

    Each tag file must have a corresponding entry in a TLD file.

    B.

    All directives allowed in JSP pages are allowed in Tag Files.

    C.

    All directives allowed in Tag Files are allowed in JSP pages.

    D.

    The <jsp:doBody> standard action can only be used in Tag Files.

    E.

    The allowable file extensions for Tag Files are .tag and .tagx.

    F.

    For each attribute declared and specified in a Tag File, the container creates a page-scoped attribute with the same name.

  18. Which are valid in tag files? (Choose all that apply.)

    A.

    <jsp:doBody />

    B.

    <jsp:invoke fragment="frag" />

    C.

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

    D.

    <%@ variable name-given="date"
        variable-class="java.util.Date" %>

    E.

    <%@ attribute name="name" value="blank"
        type="java.lang.String" %>
  19. Which returns the enclosing tag when called from within a tag handler class? (Choose all that apply.)

    A.

    getParent()

    B.

    getAncestor()

    C.

    findAncestor()

    D.

    getEnclosingTag()

  20. Given a web application structure:

    /WEB-INF/tags/mytags/tag1.tag
    /WEB-INF/tags/tag2.tag
    /WEB-INF/tag3.tag
    /tag4.tag

    Which tags could be used by an appropriate taglib directive? (Choose all that apply.)

    A.

    tag1.tag

    B.

    tag2.tag

    C.

    tag3.tag

    D.

    tag4.tag

  21. A web application includes many forms for users to fill out and submit. Nothing in the pages indicates that a field is required. Business decided that a red asterisk should be placed preceding the text labels of required fields but the project manager is contending that the background color of required fields be light blue and another department is demanding that the project’s application be consistent with their own, where the text of the labels be bold for required fields.

    Considering the different perspectives on how required fields could be identified in pages, choose the most maintainable usage of a custom tag.

    A.

    <cust:requiredIcon/>First Name: <input type="text"
           name="firstName"/>

    B.

    <cust:textField label="First Name" required="true"/>

    C.

    <cust:requiredField color="red" symbol="*"
           label="First Name"/>

    D.

    <cust:required>
      First Name: <input type="text" name="firstName"/>
    </cust:required>
..................Content has been hidden....................

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