Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Body Content Problem

 
Michael Santosa
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a bit confused about the Body Content,
here is the piece of codes :
int doAfterTag() throws JspTagException
{
BodyContent bc = getBodyContent();
bc.getEnclosingWriter().println("Test 123");
pageContext.getOut().print("Test 123");
...
So my question is what is the different
between :
bc.getEnclosingWriter().println("Test 123");
and
pageContext.getOut().print("Test 123");
?
And I test that :
bc.getEnclosingWriter().println("Test 123");
Only prints the data out dan doesn't change
the body.
The second question is :
What is the uses of :
out = pageContext.pushBody();
out = pageContext.popBody();
??
(I saw it on generated Servlet).
Does pushBody put the content of the body
into stack, and popBody get the body
again from the Stack ?
Thank you for the help.. I really appreciate it
[ April 26, 2002: Message edited by: Michael Santosa ]
 
Aaradhna Saxena
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"pushBody()" pushes the current "out" object available to the JSP page on the stack and returns the "bodyContent" object that is eventaully passed on to the tag handler by invoking the "setBodyContent()" method.
bodyContent actually extends JspWriter and it simply provides a kind of play area for the BodyTag implementing handlers, where the body content can be manipulated without actually affecting the JspWRiter of the enclosing JSP page.
The actual content of the bodyContent can be obtained as a String using "getString()" method or as a Reader using the "getReader()" method or it can be written to a writer using "writeOut(Writer w)" method. To write to the client's response thr writeOut method has the enclosing JspWriter object which is obtained by calling the "getEnclosingWriter()" method.
I hope this helps you...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic