Free SCWCD Mock Exam for Custom Tags


This practice exam focuses on Custom Tags. For those using Head First Servlets and JSP, 2nd Edition it is a perfect companion for chapter 10.

Custom Tags is the most powerful feature of the JSP technology. This free material should be useful for those preparing for the Sun Certified Web Component Developer certification.

To get basic skills before going on, you may consider this compact tutorial first.

  1. Is this a valid use of header.tag, a JSP tag file that is located in WEB-INF/tags? (1 correct answer)
    <%@ taglib prefix="my" tagdir="/WEB-INF/tags" %>
    <html>
      <body>
        <my:header />
      </body>
    </html>
    
    1. Yes.
    2. No.

  2. Is this a valid use of header.tag, a JSP tag file that is located in WEB-INF/tags? (1 correct answer)
    <%@ taglib prefix="my" tagdir="/WEB-INF/tags/
    
    header.tag" %> <html>   <body>     <my:header />   </body> </html>
    1. Yes.
    2. No.

  3. Is this a valid use of header.tag, a JSP tag file that is located in WEB-INF/tags? (1 correct answer)
    <%@ taglib prefix="my" uri="/WEB-INF/tags" %>
    <html>
      <body>
        <my:header />
      </body>
    </html>
    
    1. Yes.
    2. No.

  4. Is this a valid use of header.tag, a JSP tag file that is located in WEB-INF/tags? (1 correct answer)
    <%@ taglib prefix="my" uri="/WEB-INF/tags/
    
    header.tag" %> <html>   <body>     <my:header />   </body> </html>
    1. Yes.
    2. No.

  5. Is this a valid use of header.tag, a JSP tag file that is located in WEB-INF/tags? (1 correct answer)
    <%@ taglib prefix="my" tagdir="/WEB-INF/tags/"
    
    uri="https://nikojava.wordpress.com" %> <html>   <body>     <my:header />   </body> </html>
    1. Yes.
    2. No.

  6. Is this a valid use of header.tag, a JSP tag file that is located in WEB-INF/tags? (1 correct answer)
    <%@ taglib prefix="header" tagdir="/WEB-INF/
    tags" %>
    <html>
      <body>
        <header:header />
      </body>
    </html>
    
    1. Yes.
    2. No.

  7. Is this a valid use of header.tag, a JSP tag file that is located in WEB-INF/tags? (1 correct answer)
    <%@ taglib prefix="1" tagdir="/WEB-INF/tags" %>
    <html>
      <body>
        <1:header />
      </body>
    </html>
    
    1. Yes.
    2. No.

  8. Consider these files.
    <%-- WEB-INF/tags/header.tag --%>
    <h1>Hello !!</h1>
    
    <%-- output.jsp --%>
    <%@ taglib prefix="my" tagdir="/WEB-INF/tags" %>
    <html>
      <body>
        <my:header></my:header>
      </body>
    </html>
    

    Is the declaration and use of the JSP tag file valid? (1 correct answer)

    1. Yes.
    2. No.

  9. Consider these files.
    <%-- WEB-INF/tags/header.tag --%>
    <h1>Hello ${Manoli}!!</h1>
    
    <%-- output.jsp --%>
    <%@ taglib prefix="my" tagdir="/WEB-INF/tags" %>
    <html>
      <body>
        <my:header name="Manoli"/>
      </body>
    </html>
    

    Is the declaration and use of the JSP tag file valid? (1 correct answer)

    1. Yes.
    2. No.

  10. Consider these files.
    <%-- WEB-INF/tags/header.tag --%>
    <h1>Hello ${name}!!</h1>
    
    <%-- output.jsp --%>
    <%@ taglib prefix="my" tagdir="/WEB-INF/tags" %>
    <html>
      <body>
        <my:header name="Manoli"/>
      </body>
    </html>
    

    Is the declaration and use of the JSP tag file valid? (1 correct answer)

    1. Yes.
    2. No.

  11. Consider these files.
    <%-- WEB-INF/tags/header.tag --%>
    <%@ attribute name="name" %>
    <h1>Hello ${name}!!</h1>
    
    <%-- output.jsp --%>
    <%@ taglib prefix="my" tagdir="/WEB-INF/tags" %>
    <html>
      <body>
        <my:header name="Manoli"/>
      </body>
    </html>
    

    Is the declaration and use of the JSP tag file valid? (1 correct answer)

    1. Yes.
    2. No.

  12. Consider these files.
    <%-- WEB-INF/tags/header.tag --%>
    <%@ attribute name="name" %>
    <h1>Hello ${name}!!</h1>
    
    <%-- output.jsp --%>
    <%@ taglib prefix="my" tagdir="/WEB-INF/tags" %>
    <html>
      <body>
        <my:header name="Manoli"></my:header>
      </body>
    </html>
    

    Is the declaration and use of the JSP tag file valid? (1 correct answer)

    1. Yes.
    2. No.

  13. Consider these files.
    <%-- WEB-INF/tags/simple.tag --%>
    <%@ attribute name="city" required="false" %>
    <%@ tag pageEncoding="utf-8"%>
    This is ${city}.
    
    <%-- output.jsp --%>
    <%@ taglib prefix="ayo" tagdir="/WEB-INF/tags" %>
    <html>
      <body>
        <ayo:simple city="Sparta"/>
      </body>
    </html>
    

    What is the output? (1 correct answer)

    1. “This is .”
    2. “This is Sparta.”
    3. An exception occurs at runtime.

  14. Consider these files.
    <%-- WEB-INF/tags/simple.tag --%>
    <%@ attribute name="city" required="true" %>
    <%@ tag pageEncoding="utf-8"%>
    This is ${city}.
    
    <%-- output.jsp --%>
    <%@ taglib prefix="ayo" tagdir="/WEB-INF/tags" %>
    <html>
      <body>
        <ayo:simple/>
      </body>
    </html>
    

    What is the output? (1 correct answer)

    1. “This is .”
    2. “This is Sparta.”
    3. An exception occurs at runtime.

  15. Consider these files.
    <%-- WEB-INF/tags/simple.tag --%>
    <%@ attribute name="city" %>
    <%@ tag pageEncoding="utf-8"%>
    This is ${city}.
    
    <%-- output.jsp --%>
    <%@ taglib prefix="ayo" tagdir="/WEB-INF/tags" %>
    <% request.setAttribute("city", "Sparta");%>
    <html>
      <body>
        <ayo:simple city="${city}"/>
      </body>
    </html>
    

    What is the output? (1 correct answer)

    1. “This is .”
    2. “This is Sparta.”
    3. An exception occurs at runtime.

  16. Consider these files.
    <%-- WEB-INF/tags/simple.tag --%>
    <%@ attribute name="city" rtexprvalue="false" %>
    <%@ tag pageEncoding="utf-8"%>
    This is ${city}.
    
    <%-- output.jsp --%>
    <%@ taglib prefix="ayo" tagdir="/WEB-INF/tags" %>
    <% request.setAttribute("city", "Sparta");%>
    <html>
      <body>
        <ayo:simple city="${city}"/>
      </body>
    </html>
    

    What is the output? (1 correct answer)

    1. “This is .”
    2. “This is Sparta.”
    3. An exception occurs at runtime.

  17. Consider these files.
    <%-- WEB-INF/tags/simple.tag --%>
    <%@ attribute name="city" rtexprvalue="true" %>
    <%@ tag pageEncoding="utf-8"%>
    This is ${city}.
    
    <%-- output.jsp --%>
    <%@ taglib prefix="ayo" tagdir="/WEB-INF/tags" %>
    <html>
      <body>
        <ayo:simple city="${1 ge 10}"/>
      </body>
    </html>
    

    What is the output? (1 correct answer)

    1. “This is true.”
    2. “This is false.”
    3. An exception occurs at runtime.

  18. Consider these files.
    <%-- WEB-INF/tags/simple.tag --%>
    <%@ attribute name="city" rtexprvalue="true" %>
    <%@ tag pageEncoding="utf-8"%>
    This is ${city}.
    
    <%-- output.jsp --%>
    <%@ taglib prefix="ayo" tagdir="/WEB-INF/tags" %>
    <html>
      <body>
        <ayo:simple capital="${1 ge 10}"/>
      </body>
    </html>
    

    What is the output? (1 correct answer)

    1. “This is true.”
    2. “This is false.”
    3. An exception occurs at runtime.

  19. Consider these files.
    <%-- WEB-INF/tags/body.tag --%>
    Start <jsp:doBody /> End
    
    <%-- output.jsp --%>
    <%@ taglib prefix="ayo" tagdir="/WEB-INF/tags" %>
    <html>
      <body>
        <ayo:body>Middle</ayo:body>
      </body>
    </html>
    

    What is the output? (1 correct answer)

    1. “Start End”
    2. “Start Middle End”
    3. An exception occurs at runtime.

  20. Consider these files.
    <%-- WEB-INF/tags/body.tag --%>
    <%@ tag body-content="scriptless" %>
    Start <jsp:doBody /> End
    
    <%-- output.jsp --%>
    <%@ taglib prefix="ayo" tagdir="/WEB-INF/tags" %>
    <% request.setAttribute("position", "Middle"); %>
    <html>
      <body>
        <ayo:body>${position}</ayo:body>
      </body>
    </html>
    

    What is the output? (1 correct answer)

    1. “Start End”
    2. “Start Middle End”
    3. An exception occurs at runtime.

  21. Consider these files.
    <%-- WEB-INF/tags/body.tag --%>
    <%@ tag body-content="tagdependent" %>
    Start <jsp:doBody /> End
    
    <%-- output.jsp --%>
    <%@ taglib prefix="ayo" tagdir="/WEB-INF/tags" %>
    <% request.setAttribute("position", "Middle"); %>
    <html>
      <body>
        <ayo:body><%= request.getAttribute("position") %></ayo:body>
      </body>
    </html>
    

    What is the output? (1 correct answer)

    1. “Start End”
    2. “Start Middle End”
    3. An exception occurs at runtime.

  22. SimpleTagSupport is a class that belongs to package javax.servlet.jsp.tagext. (1 correct answer)
    1. true
    2. false

  23. SimpleTagSupport IS-A SimpleTag. (1 correct answer)
    1. true
    2. false

  24. SimpleTagSupport IS-A JspTag. (1 correct answer)
    1. true
    2. false

  25. How many times is the doTag() method of SimpleTagSupport called on each tag invocation? (1 correct answer)
    1. One.
    2. It depends on the container.

  26. Consider class SimpleTagSupport. What is the signature of its method doTag? (1 correct answer)
    1. public void doTag() throws ServletException
    2. public void doTag() throws IOException, JspException

  27. Consider a simple tag handler that is nested, has attributes and a body. Here are the actions taken by the Container when this tag is invoked. Place them in the correct order starting from what happens first.
    1. Calls the setJspBody(JspFragment).
    2. Calls the no-arg constructor.
    3. Calls the doTag() method.
    4. Calls the setParent(JspTag).
    5. Calls the attribute setters.
    6. Calls the setJspContext(JspContext).

  28. Assuming all imports are correct, will this code compile successfully? (1 correct answer)
    public class Test extends SimpleTagSupport {
    public void doTag() throws IOException, JspException {
        getJspContext().getOut().println("A simple tag handler!!");
    }
    }
    
    1. Yes.
    2. No.

  29. Assuming all imports are correct, will this code compile successfully? (1 correct answer)
    public class Test extends SimpleTagSupport {
    public void doTag() throws IOException, JspException {
        getJspContext().getOut().append("A simple tag handler!!");
    }
    }
    
    1. Yes.
    2. No.

  30. Assuming all imports are correct, will this code compile successfully? (1 correct answer)
    public class Test extends SimpleTagSupport {
    public void doTag() throws IOException, JspException {
        getJspContext().getOut().format("A simple tag handler!!");
    }
    }
    
    1. Yes.
    2. No.

  31. Assuming all imports are correct, will this code compile successfully? (1 correct answer)
    public class Test extends SimpleTagSupport {
    public void doTag() throws IOException {
        getJspContext().getOut().print("A simple tag handler!!");
    }
    }
    
    1. Yes.
    2. No.

  32. Assuming all imports are correct, will this code compile successfully? (1 correct answer)
    public class Test extends SimpleTagSupport {
    public void doTag() throws Exception {
        getJspContext().getOut().print("A simple tag handler!!");
    }
    }
    
    1. Yes.
    2. No.

  33. Is this code a valid simple tag handler? (1 correct answer)
    public class Test extends SimpleTagSupport {
    public Test(String name) {
    }
    public void doTag() throws IOException, JspException {
        getJspContext().getOut().println("A simple tag handler!!");
    }
    }
    
    1. Yes.
    2. No.

  34. Test IS-A SimpleTagSupport in package simpletaghandlers. Is it correctly declared in a TLD? (1 correct answer)
    <tag>
      <tag-class>simpletaghandlers.Test</tag-class>
      <body-content>empty</body-content>
    </tag>
    
    1. Yes.
    2. No.

  35. Test IS-A SimpleTagSupport in package simpletaghandlers. Is it correctly declared in a TLD? (1 correct answer)
    <tag>
      <name>simple</name>
      <body-content>empty</body-content>
    </tag>
    
    1. Yes.
    2. No.

  36. Test IS-A SimpleTagSupport in package simpletaghandlers. Is it correctly declared in a TLD? (1 correct answer)
    <tag>
      <name>simple</name>
      <tag-class>Test</tag-class>
      <body-content>empty</body-content>
    </tag>
    
    1. Yes.
    2. No.

  37. Test IS-A SimpleTagSupport in package simpletaghandlers. Is it correctly declared in a TLD? (1 correct answer)
    <tag>
      <name>simple</name>
      <tag-class>simpletaghandlers.Test</tag-class>
    </tag>
    
    1. Yes.
    2. No.

  38. Test IS-A SimpleTagSupport in package simpletaghandlers. Is it correctly declared in a TLD? (1 correct answer)
    <tag>
      <name>simple</name>
      <tag-class>simpletaghandlers.Test</tag-class>
      <body-content>empty</body-content>
    </tag>
    
    1. Yes.
    2. No.

  39. mytaglib.tld is a valid TLD with <uri>/webapp/mytaglib</uri> and a simple tag handler with <name>simple</name>. Is this a valid use of the tag handler? (1 correct answer)
    <%@ taglib tagdir="/WEB-INF/" prefix="show"%>
    <html>
      <body>
        <show:simple />
      </body>
    </html>
    
    1. Yes.
    2. No.

  40. mytaglib.tld is a valid TLD with <uri>/webapp/mytaglib</uri> and a simple tag handler with <name>simple</name>. Is this a valid use of the tag handler? (1 correct answer)
    <%@ taglib tagdir="/WEB-INF/mytaglib.tld" prefix="show"%>
    <html>
      <body>
        <show:simple />
      </body>
    </html>
    
    1. Yes.
    2. No.

  41. mytaglib.tld is a valid TLD with <uri>/webapp/mytaglib</uri> and a simple tag handler with <name>simple</name>. Is this a valid use of the tag handler? (1 correct answer)
    <%@ taglib tagdir="/webapp/mytaglib" prefix="show"%>
    <html>
      <body>
        <show:simple />
      </body>
    </html>
    
    1. Yes.
    2. No.

  42. mytaglib.tld is a valid TLD with <uri>/webapp/mytaglib</uri> and a simple tag handler with <name>simple</name>. Is this a valid use of the tag handler? (1 correct answer)
    <%@ taglib uri="/webapp/mytaglib" prefix="show"%>
    <html>
      <body>
        <show:simple />
      </body>
    </html>
    
    1. Yes.
    2. No.

  43. Assume that everything is declared properly and the TLD specifies <body-content>scriptless</body-content>. What is the output of the JSP? (1 correct answer)
    public class Repeater extends SimpleTagSupport {
      public void doTag() throws JspException, IOException {
        getJspBody().invoke(null);
      }
    }
    
    <%@ taglib uri="/webapp/mytaglib" prefix="do" %>
    <html>
      <body>
        (Before)
        <do:repeater />
        (After)
      </body>
    </html>
    
    1. (Before)(After)
    2. An exception occurs at runtime.

  44. Assume that everything is declared properly and the TLD specifies <body-content>scriptless</body-content>. What is the output of the JSP? (1 correct answer)
    public class Repeater extends SimpleTagSupport {
      public void doTag() throws JspException, IOException {
        if (getJspBody() == null) {
          getJspContext().getOut().print("Surprise");
        } else {
          getJspBody().invoke(null);
        }
      }
    }
    
    <%@ taglib uri="/webapp/mytaglib" prefix="do" %>
    <html>
      <body>
        (Before)
        <do:repeater></do:repeater>
        (After)
      </body>
    </html>
    
    1. (Before)(After)
    2. (Before)Surprise(After)
    3. An exception occurs at runtime.

  45. Assume that everything is declared properly and the TLD specifies <body-content>scriptless</body-content>. What is the output of the JSP? (1 correct answer)
    public class Repeater extends SimpleTagSupport {
      public void doTag() throws JspException, IOException {
        getJspBody().invoke(null);
      }
    }
    
    <%@ taglib uri="/webapp/mytaglib" prefix="do" %>
    <html>
      <body>
        (Before)
        <do:repeater>Surprise</do:repeater>
        (After)
      </body>
    </html>
    
    1. (Before)(After)
    2. (Before)Surprise(After)
    3. An exception occurs at runtime.

  46. Assume that everything is declared properly and the TLD specifies <body-content>empty</body-content>. What is the output of the JSP? (1 correct answer)
    public class Repeater extends SimpleTagSupport {
      public void doTag() throws JspException, IOException {
        getJspBody().invoke(null);
      }
    }
    
    <%@ taglib uri="/webapp/mytaglib" prefix="do" %>
    <html>
      <body>
        (Before)
        <do:repeater>Surprise</do:repeater>
        (After)
      </body>
    </html>
    
    1. (Before)(After)
    2. (Before)Surprise(After)
    3. An exception occurs at runtime.

  47. Assume that everything is declared properly and the TLD specifies <body-content>scriptless</body-content>. What is the output of the JSP? (1 correct answer)
    public class Repeater extends SimpleTagSupport {
      public void doTag() throws JspException, IOException {
        getJspBody().invoke(null);
        getJspBody().invoke(null);
      }
    }
    
    <%@ taglib uri="/webapp/mytaglib" prefix="do" %>
    <html>
      <body>
        (Before)
        <do:repeater>Surprise</do:repeater>
        (After)
      </body>
    </html>
    
    1. (Before)(After)
    2. (Before)Surprise(After)
    3. (Before)SurpriseSurprise(After)
    4. An exception occurs at runtime.

  48. Assume that everything is declared properly and the TLD specifies <body-content>scriptless</body-content>. What is the output of the JSP? (1 correct answer)
    public class Repeater extends SimpleTagSupport {
      public void doTag() throws JspException, IOException {
        getJspBody().invoke(null);
      }
    }
    
    <%@ taglib uri="/webapp/mytaglib" prefix="do" %>
    <html>
      <body>
        (Before)
        <do:repeater>${here}</do:repeater>
        (After)
      </body>
    </html>
    
    1. (Before)(After)
    2. (Before)here(After)
    3. (Before)${here}(After)
    4. An exception occurs at runtime.

  49. Assume that everything is declared properly and the TLD specifies <body-content>scriptless</body-content>. What is the output of the JSP? (1 correct answer)
    public class Repeater extends SimpleTagSupport {
      public void doTag() throws JspException, IOException {
        getJspBody().invoke(null);
      }
    }
    
    <%@ taglib uri="/webapp/mytaglib" prefix="do" %>
    <% request.setAttribute("here", "Surprise"); %>
    <html>
      <body>
        (Before)
        <do:repeater>${here}</do:repeater>
        (After)
      </body>
    </html>
    
    1. (Before)(After)
    2. (Before)Surprise(After)
    3. An exception occurs at runtime.

  50. Assume that everything is declared properly and the TLD specifies <body-content>scriptless</body-content>. What is the output of the JSP? (1 correct answer)
    public class Repeater extends SimpleTagSupport {
      public void doTag() throws JspException, IOException {
        getJspContext().setAttribute("here", "Surprise");
        getJspBody().invoke(null);
      }
    }
    
    <%@ taglib uri="/webapp/mytaglib" prefix="do" %>
    <html>
      <body>
        (Before)
        <do:repeater>${here}</do:repeater>
        (After)
      </body>
    </html>
    
    1. (Before)(After)
    2. (Before)Surprise(After)
    3. An exception occurs at runtime.

  51. Consider this simple tag handler
    public class Repeater extends SimpleTagSupport {
      private String surprise;
      public void doTag() throws JspException, IOException {
        getJspContext().getOut().print(surprise);
        getJspContext().getOut().print(" is a big surprise!");
      }
    }
    

    that is properly declared in a TLD with the following attribute.

    <attribute>
      <name>surprise</name>
      <required>false</required>
      <rtexprvalue>false</rtexprvalue>
    </attribute>
    

    What is the output of this JSP? (1 correct answer)

    <%@ taglib uri="/webapp/mytaglib" prefix="do" %>
    <html>
      <body>
        (Before)
        <do:repeater surprise="NetBeans 6.5" />
        (After)
      </body>
    </html>
    
    1. (Before)(After)
    2. (Before)null is a big surprise!(After)
    3. (Before)NetBeans 6.5 is a big surprise!(After)
    4. An exception occurs at runtime.

  52. Consider this simple tag handler
    public class Repeater extends SimpleTagSupport {
      private String surprise;
      public void doTag() throws JspException, IOException {
        getJspContext().getOut().print(surprise);
        getJspContext().getOut().print(" is a big surprise!");
      }
      public void setSurprise(String surprise) {
      }
    }
    

    that is properly declared in a TLD with the following attribute.

    <attribute>
      <name>surprise</name>
      <required>false</required>
      <rtexprvalue>false</rtexprvalue>
    </attribute>
    

    What is the output of this JSP? (1 correct answer)

    <%@ taglib uri="/webapp/mytaglib" prefix="do" %>
    <html>
      <body>
        (Before)
        <do:repeater surprise="NetBeans 6.5" />
        (After)
      </body>
    </html>
    
    1. (Before)(After)
    2. (Before)null is a big surprise!(After)
    3. (Before)NetBeans 6.5 is a big surprise!(After)
    4. An exception occurs at runtime.

  53. Consider this simple tag handler
    public class Repeater extends SimpleTagSupport {
      private String surprise;
      public void doTag() throws JspException, IOException {
        getJspContext().getOut().print(surprise);
        getJspContext().getOut().print(" is a big surprise!");
      }
      public void setSurprise(String surprise) {
        this.surprise = surprise;
      ;}
    }
    

    that is properly declared in a TLD with the following attribute.

    <attribute>
      <name>surprise</name>
      <required>false</required>
      <rtexprvalue>false</rtexprvalue>
    </attribute>
    

    What is the output of this JSP? (1 correct answer)

    <%@ taglib uri="/webapp/mytaglib" prefix="do" %>
    <html>
      <body>
        (Before)
        <do:repeater surprise="NetBeans 6.5" />
        (After)
      </body>
    </html>
    
    1. (Before)(After)
    2. (Before)null is a big surprise!(After)
    3. (Before)NetBeans 6.5 is a big surprise!(After)
    4. An exception occurs at runtime.

  54. TagSupport is a class that belongs to package javax.servlet.jsp.tagext. (1 correct answer)
    1. true
    2. false

  55. TagSupport IS-A IterationTag. (1 correct answer)
    1. true
    2. false

  56. TagSupport IS-A Tag. (1 correct answer)
    1. true
    2. false

  57. TagSupport IS-A JspTag. (1 correct answer)
    1. true
    2. false

  58. Consider class TagSupport. What is the signature of its method doStartTag? (1 correct answer)
    1. public int doStartTag() throws JspException
    2. public void doStartTag() throws JspException
    3. public int doStartTag() throws JspException, IOException
    4. public void doStartTag() throws JspException, IOException

  59. Consider class TagSupport. What is the signature of its method doEndTag? (1 correct answer)
    1. public int doEndTag() throws JspException
    2. public int doEndTag(String) throws JspException
    3. public int doEndTag(Writer) throws JspException, IOException

  60. Consider interface IterationTag. What is the signature of its method doAfterBody? (1 correct answer)
    1. int doAfterBody() throws JspException
    2. void doAfterBody() throws JspException

  61. The following are all fields of interface Tag. (1 correct answer)
          ⇒ SKIP_BODY
          ⇒ SKIP_PAGE
          ⇒ EVAL_PAGE
          ⇒ EVAL_BODY_INCLUDE

    1. true
    2. false

  62. The following is a field of interface IterationTag. (1 correct answer)
          ⇒ EVAL_BODY_AGAIN

    1. true
    2. false

  63. Is this a valid classic tag handler? (1 correct answer)
    public class Classic extends TagSupport {
    }
    
    1. Yes.
    2. No.

  64. Is this a valid classic tag handler? (1 correct answer)
    public class Classic extends TagSupport {
        public Classic() {
        }
    }
    
    1. Yes.
    2. No.

  65. Is this a valid classic tag handler? (1 correct answer)
    public class Classic extends TagSupport {
        private Classic() {
        }
    }
    
    1. Yes.
    2. No.

  66. Is this a valid classic tag handler? (1 correct answer)
    public class Classic extends TagSupport {
        public Classic() {
        }
        public Classic(String construct) {
        }
    }
    
    1. Yes.
    2. No.

  67. Assume that everything is declared properly and the TLD specifies <body-content>scriptless</body-content>. What is the output of the JSP? (1 correct answer)
    public class Classic extends TagSupport {
      public int doStartTag() {
        return SKIP_BODY;
      }
    }
    
    <%@ taglib uri="correct" prefix="yes" %>
    <html>
      <body>
        (Before)
        <yes:classic>My Body</yes:classic>
        (After)
      </body>
    </html>
    
    1. (Before)(After)
    2. (Before)My Body(After)

  68. Assume that everything is declared properly and the TLD specifies <body-content>scriptless</body-content>. What is the output of the JSP? (1 correct answer)
    public class Classic extends TagSupport {
      public int doStartTag() {
        return SKIP_PAGE;
      }
    }
    
    <%@ taglib uri="correct" prefix="yes" %>
    <html>
      <body>
        (Before)
        <yes:classic>My Body</yes:classic>
        (After)
      </body>
    </html>
    
    1. (Before)(After)
    2. (Before)
    3. (Before)My Body(After)
    4. (Before)My Body

  69. Assume that everything is declared properly and the TLD specifies <body-content>scriptless</body-content>. What is the output of the JSP? (1 correct answer)
    public class Classic extends TagSupport {
      public int doStartTag() {
        return EVAL_BODY_INCLUDE;
      }
    }
    
    <%@ taglib uri="correct" prefix="yes" %>
    <html>
      <body>
        (Before)
        <yes:classic>My Body</yes:classic>
        (After)
      </body>
    </html>
    
    1. (Before)(After)
    2. (Before)
    3. (Before)My Body(After)
    4. (Before)My Body

  70. Assume that everything is declared properly and the TLD specifies <body-content>scriptless</body-content>. What is the output of the JSP? (1 correct answer)
    public class Classic extends TagSupport {
      public int doStartTag() {
        try {
          pageContext.getOut().print("Hello!!");
        } catch (Exception e) {
          e.printStackTrace();
        }
        return SKIP_BODY;
      }
    }
    
    <%@ taglib uri="correct" prefix="yes" %>
    <html>
      <body>
        (Before)
        <yes:classic>My Body</yes:classic>
        (After)
      </body>
    </html>
    
    1. (Before)(After)
    2. (Before)Hello!!(After)
    3. (Before)My Body(After)
    4. (Before)Hello!!My Body(After)

  71. Assume that everything is declared properly and the TLD specifies <body-content>scriptless</body-content>. What is the output of the JSP? (1 correct answer)
    public class Classic extends TagSupport {
      public int doStartTag() {
        try {
          pageContext.getOut().print("Hello!!");
        } catch (Exception e) {
          e.printStackTrace();
        }
        return EVAL_BODY_INCLUDE;
      }
    }
    
    <%@ taglib uri="correct" prefix="yes" %>
    <html>
      <body>
        (Before)
        <yes:classic>My Body</yes:classic>
        (After)
      </body>
    </html>
    
    1. (Before)(After)
    2. (Before)Hello!!(After)
    3. (Before)My Body(After)
    4. (Before)Hello!!My Body(After)

  72. This classic tag handler is properly declared in a TLD.
    public class Classic extends TagSupport {
      private List<String> movies = new ArrayList<String>();
      private int current = 0;
      public ClassicRepeater() {
        movies.add("Heat");
        movies.add("Pocahontas");
        movies.add("Lawrence of Arabia");
      }
      public int doStartTag() {
        setAttribute();
        return EVAL_BODY_INCLUDE;
      }
      public int doAfterBody() {
        while (current < movies.size()) {
          setAttribute();
          return EVAL_BODY_AGAIN;
        }
        return SKIP_BODY;        
      }
      private void setAttribute() {
        pageContext.setAttribute("movie", movies.get(current));                
        current++;
      }
    }
    

    Many testers complain that when they visit or repeatedly hit the refresh button on the following jsp, they sometimes get an IndexOutOfBoundsException. What’s wrong with the above implementation? (1 correct answer)

    <%@ taglib uri="correct" prefix="yes" %>
    <html>
      <body>
        <ol>
        <yes:classic><li>${movie}</li></yes:classic>
        </ol>
      </body>
    </html>
    
    1. We should override the doEndTag() method.
    2. The value returned by doStartTag() is not correct.
    3. The doAfterBody() should not have a while loop inside.
    4. The instance variables should be initialized in the doStartTag() method.
    5. The doStartTag() and doAfterBody() methods should throw a JspException.

© 2008-2009 Nikos Pougounias. A free contribution to the Java community. Please distribute it for free. https://nikojava.wordpress.com

Answers

  1. a
  2. b
  3. b
  4. b
  5. b
  6. a
  7. a
  8. a
  9. b
  10. b
  11. a
  12. a
  13. b
  14. c
  15. b
  16. c
  17. b
  18. c
  19. b
  20. b
  21. c
  22. a
  23. a
  24. a
  25. a
  26. b
  27. b, f, d, e, a, c
  28. a
  29. a
  30. b
  31. a
  32. b
  33. b
  34. b
  35. b
  36. b
  37. b
  38. a
  39. b
  40. b
  41. b
  42. a
  43. b
  44. b
  45. b
  46. c
  47. c
  48. a
  49. b
  50. b
  51. d
  52. b
  53. c
  54. a
  55. a
  56. a
  57. a
  58. a
  59. a
  60. a
  61. a
  62. a
  63. a
  64. a
  65. b
  66. a
  67. a
  68. c
  69. c
  70. b
  71. d
  72. d

6 Responses to Free SCWCD Mock Exam for Custom Tags

  1. Bindu says:

    Qn 68 : returning SKIP_PAGE from doStartTag()
    evaluates the body?
    How so?
    Please explain?
    And make corrections in question 52 and 53.You are defining a method with in a method in them.

  2. Vishwa says:

    Hi ! An excellent quiz. Makes familiarizing with code very easy!

    Thanks!

    *qn 37: isnt it a valid TLD declaration? is optional rite?

  3. […] Free SCWCD Mock Exam for Custom Tags […]

  4. hassan says:

    Thanks for this good quiz!

    Regarding Question #21: You state that option c (An exception occurs at runtime.) is the correct answer.
    I’v tried out the sample. The correct answer would be:

    output is

    d) Start End

    Reason: body-content is tagedependent, so the body won’t be evaluated and obviously moreover the body allows scriptlets.

    Agree?

  5. hassan says:

    Thanks for this good quiz!

    Regarding Question #21: You state that option c (An exception occurs at runtime.) is the correct answer.
    I’v tried out the sample. The correct answer would be:

    output is

    d) “Start End”

    Reason: body-content is tagedependent, so the body will be generated as template text and obviously moreover the body allows scriptlets.

    Agree?

    (To avoid confusion you can remove my first posting on that topic )

  6. Matthew Smart says:

    @Bindu, SKIP_PAGE can only be returned from doEndTag(). Trying to return it from doStartTag() has no effect and the body is included in the response.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: