• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A mock question on custom tags

 
L Yan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I came across this mock question on the custom tags.

Given the following tag handler defined with <body-content>JSP</body-content>,

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>

A.The tag handler won't compile.
B.The jsp page will print Hello how are you?
C.The jsp page will print how are you? Hello
D.The jsp page will print Hello

The given correct answer is D. I tried the code, it doesn't print anything. Do you have any ideas?

Thank you
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also think that it won't print anything.
doStartTag() is not overriden, so the default return value is EVAL_BODY_BUFFERED. pushBody() is called on the pageContent, so all output will be sent to the BodyContent. So nothing appears on the jsp page.
 
L Yan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Satou.

BTW: I don't think the advanced features of Classic Tags are covered in HFSJ, such as pushBody(). Do you know it is required in the actual exam?
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the exam takers say that you will see roughly two questions on custom tags
and these also would be relevant to the things in HFSJ ! so rest assured
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic