Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

dostartTag return value doubt

 
Parth Twari
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Niko's question

Q.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

Answer: 3

I tested it and its working fine! yes the answer comes out as 3 only but why? What i have read as valid return types for doStartTag are SKIP_BODY and EVAL_BODY_INCLUDE but its working correctly here. Can anyone explain why?
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2264
76
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Parth,

These are really trick questions that you won't come across on the real exam, don't worry about them too much.

First of all: it compiles because SKIP_PAGE is defined as a public static final int, the compiler doesn't know whether that value applies in this method
Secondly: it runs because the generated Servlet checks only on whether the body should be skipped: see part of the generated code (on tomcat):

The JSP2.0 spec doesn't say anything about what should be done if there is a wrong return code thrown from one the tag-methods, so I find the outcome of this question questionable.

Regards,
Frits

 
Parth Twari
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whew..so this worked because it was like this on tomcat 5

ok thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic