Forums Register Login

doAfterBody()

+Pie Number of slices to send: Send
Here is a question:-

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 ans is 4.The jsp page will print Hello

1.Why is "how are u" not getting printed??
2.If i extend BodyTagSupport then when i have to print something from inside doAfterBody() , do i have to use getBodyContent.getEnclosingWriter() ???
I am a lot confused in custom tags.If there is a good link for it, please let me know.

thanks,mallika
+Pie Number of slices to send: Send
doAfterBody() will be invoked if doStartTag() returns EVAL_BODY_BUFFERED.
+Pie Number of slices to send: Send
Hi Mallika,

Did you work this example out? The answer should be choice 2.

Satou,

doAfterBody() will also be invoked if the return is EVAL_BODY_INCLUDE. Isn't? EVAL_BODY_BUFFERED is for doInitBody(). Correct me if I am wrong.
+Pie Number of slices to send: Send
 

doAfterBody() will also be invoked if the return is EVAL_BODY_INCLUDE. Isn't?


Yes, sorry, I messed up that one, forget about my post.
Thank you for pointing this out.
+Pie Number of slices to send: Send
I ran this last night, and the output was "Hello How are you". seems like number 2 is correct. Where did this question come from?
+Pie Number of slices to send: Send
this question was ( actually i dont remember now) but guesss was in JPilot mock simulator..

so whats the correct ans..is it Hello OR hello, How are you?

mallika
+Pie Number of slices to send: Send
The answer is "hello how are you".
The only thing that kept the leeches off of me was this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 773 times.
Similar Threads
Mock test question
Help with the following ques
Custom Tag Handler
Taghandler doubt
Exam question.
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:22:16.