The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes a qustion on jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Web Component Certification (SCWCD/OCPJWCD)
Reply Bookmark "a qustion on jsp" Watch "a qustion on jsp" New topic
Author

a qustion on jsp

tony lee
Ranch Hand

Joined: Jan 21, 2002
Posts: 52
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


SCJP2, SCWCD
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
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
 
 
subject: a qustion on jsp
 
MyEclipse, The Clear Choice

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture