• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a qustion on jsp

 
tony lee
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given the following tag handler defined with <bodycontent>JSP</bodycontent>
public class body extends TagSupport {
public int doStartTag() throws JspException{
return EVAL_BODY_INCLUDE;
}
public int doAfterBody() throws JspException {
try { pageContext.getOut().print("how are you?"); }catch(IOException e) {}
return SKIP_BODY;
}
}
what will be printed out by the following part of a jsp page?
<prefix:sufix>
<i>Hello</i>
</prefix:sufix>
1) The tag handler won't compile.
2) The jsp page will print Hello how are you?
3) The jsp page will print how are you? Hello
4) The jsp page will print Hello
The answer is 3. I think it should be 2
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by tony lee:
The answer is 3. I think it should be 2
I agree with you. The spec says (p168): if an IterationTAG's doStartTag() returns EVAL_BODY_INCLUDE [...], the body is evaluated and �passed through� to the current out, then doAfterBody() is invoked and, after zero or more iterations, doEndTag() is invoked. So what should happen is that the body "Hello" is output as it is evaluated, and only then doAfterBody() is invoked and "how are you" is included.
- Peter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic