• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jdiscuss mock exam question

 
jyothi sanka
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider the tag handler class shown in exhibit.
What will be printed when the above tag is used as follows in a jsp page:

Hello <mylib:mytag> World!</mylib:mytag>

Code

public class MyTag extends TagSupport
{
public int doAfterBody()
{
try
{
pageContext.getOut().println("In doAfterBody()");
}
catch(Exception e)
{
}
return SKIP_BODY;
}
}
they gave answer is Hello.

I think answer is Hello World
because there is no doStartTag() and default is skip_body, so it goes to the doEndTag() and default value is EVAL_PAGE so World has to print.

Can anybody explain me ?
Thank you
 
Nitish Bahadur
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this is what is happening, doStartTag() of the Tag interface will always be called. Since you have not overridden it, the default implementation in TagSupport class is called. The default implementation returns Tag.SKIP_BODY. Since the body is skipped doAfterBody is NOT called.
 
Chaitanya Athanikar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think Nitish is rite.Default for doStartTag() is SKIP_BODY and hence doAfterBody() is not called and hence body is not evaluated and only Hello is printed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic