A Classic tag handler exists in legacy code. The author wrote a handler that evaluates its tag body a hundred times, to be used in testing other tags that produce random content.
Given:
06. public class HundredTimesTag extends TagSupport {
07. private int iterationCount;
08. public int doTag() throws JspException {
09. iterationCount = 0;
10. return EVAL_BODY_INCLUDE;
11. }
12.
13. public int doAfterBody() throws JspException {
14. if(iterationCount < 100){
15. iterationCount++;
16. return EVAL_BODY_AGAIN;
17. }else{
18. return SKIP_BODY;
19. }
20. }
21. }
What is incorrect about the code?
A. Tag handlers are not thread safe, so the iterationCount can become out of sync if multiple users are reaching the page at the same time.
B. The doAfterBody method is never being called because it is not part of the tag handler lifecycle. The developer should have extended the IterationTagSupport class to include this method in the lifecycle.
C. The doTag method should be doStartTag. As written, the default doStartTag of TagSupport is called which simply returns SKIP_BODY, causing doAfterBody to never be called.
D. When doAfterBody returns EVAL_BODY_AGAIN the doTag method is called again. The doTag method resets iterationCount to 0, resulting in an infinite loop and java.lang.OutOfMemoryError is thrown
Given:
01. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
02.
03. <%
04. java.util.List books = new java.util.ArrayList();
05. // add line here
06. request.setAttribute("myFavoriteBooks", books);
07. %>
08.
09. <c:choose>
10. <c:when test="${not empty myFavoriteBooks}">
11. My favorite books are:
12. <c:forEach var="book" items="${myFavoriteBooks}">
13. <br/> * ${book}
14. </c:forEach>
15. </c:when>
16. <c:otherwise>
17. I have not selected any favorite books.
18. </c:otherwise>
19. </c:choose>
Which of the following lines of code, if inserted independently at Line 5, will cause the text within the c:otherwise tag to display? (Choose all that apply)
A. books.add("");
B. books.add(null);
C. books.clear();
D. books.add("Head First");
E. books = null;
Given:
1. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/
jstl/core" %>
2. <%@ taglib prefix="tables" uri="http://www.javaranch.
com/tables" %>
3. <%@ taglib prefix="jsp" tagdir="/WEB-INF/tags" %>
4. <%@ taglib uri="UtilityFunctions" prefix="util" %>
What about the above taglib directives would cause the JSP to not function?
A. Line 4 is wrong because the prefix attribute must come before the
uri attribute.
B. Line 3 is wrong because there is no uri attribute.
C. Line 4 is wrong because the uri value must begin with http://
D. Line 3 is wrong because the prefix jsp is reserved for standard actions.
Roel De Nijs wrote:Some of them are already confirmed in this topic.
No, tomorrow we rule the world! With this tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
|