• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is this correct?

 
Renu Radhika
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question 25)
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 and hint given is

4) The jsp page will print Hello

As far as I know you can't print from doAfterBdoy in a TagSupport handlers.You could just repeat the evaluation of the body by returning EVAL_BODY_INCLUDE and stop the loop on some condition by returning SKIP_BODY.I couldn't test this last thing as I am using tomcat 3.2.3 which doesn't support jsp 1.2.

Is this correct?If we can print from dostartTag why not from doAfterBody?
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

You can print from inside of the doAfterBody() method, and to make sure, i have tested this code and it printed Hello how are you?

Best of luck ...
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Vassili!


Thanks,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic