File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Can anyone explain this to me? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Can anyone explain this to me?" Watch "Can anyone explain this to me?" New topic
Author

Can anyone explain this to me?

Renu Radhika
Ranch Hand

Joined: Oct 21, 2005
Posts: 243
Question 26)
Given the following tag handler defined with <bodycontent>JSP</bodycontent>

public class body extends BodyTagSupport {
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


Answer given is

4) The jsp page will print Hello

Inside doAfterBdoy the bodyContent is in a stack and the implicit variable out prints into the bodyContent not to the outputStream.The bodyContent keeps a reference to the buffered writer (either a enclosing bodyContent or the implicit out variable) called the previousOut.If you want to print inside doAFterBdoy you have to use this previousOut. To print things unrelated with the body use pageContext.getOut in doStartTag. By default doStartTag in BodyTagSupport returns EVAl_BODY_BUFFERED which produces a stack of bodycontents, one bodycontent for each iteration.If you don't want this stack to be create you have to override doStartTag and return EVAL_BODY_IHCLUDE, then the default out would print to the output stream (to the response).
Renu Radhika
Ranch Hand

Joined: Oct 21, 2005
Posts: 243
Can anyone help please?
Bunty
Greenhorn

Joined: Jun 14, 2006
Posts: 10
Hi
Did you notice any exception thrown in the catch block.
try to print something in the catch block or print stack trace call
I am not sure about the solution , but it may help

Bye


-Regards,<br />Bunty<br />SCJP 1.4(91%)<br />SCWCD(86%)<br />Next SCBCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can anyone explain this to me?