TLD:
<body-content>
JSP</body-content>
JSP:
<prefix:tagName>Hello</prefix:tagName>
Case 1:
Tag Handler:
public class TextTag extends BodyTagSupport{
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;
}
}
Output:
Hello How are you?
Case 2:
Tag Handler:
public class TextTag extends BodyTagSupport{
public int doStartTag() throws JspException {
return EVAL_BODY_BUFFERED;
}
public int doAfterBody() throws JspException {
try {
pageContext.getOut().print("How are you?");
}catch(IOException e) {}
return SKIP_BODY;
}
}
Output:
Nothing gets printed.
If I add the following code, �Hello How are you?� gets printed
JspWriter out = getBodyContent().getEnclosingWriter();
out.print(getBodyContent().getString());
out().print("How are you?");
What is the difference between pageContext.getOut and JspWriter got from getEnclosingWriter()? The behavior differs only when I return EVAL_BODY_BUFFERED from doStartTag().
Can someone please explain me the concept.