• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help with the following ques

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
According to the answer..it still prints "Hello"
Why is this so???. As the doStart TAg method returns eval_body_include..should'nt it print hello how are u....
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe the doAfterBody return of SKIP_BODY might answer the questions. Kind of a trick question there.
Mark
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok..
becoz doStartTag says eval_body_include it evaluates the body but there is a print statement in doAfterBody ..which comes before "return skip_body" then should'nt it print "how are u" and skip the body
This is still not clear..please explain
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See, the class dosen't extend BodyTagSupport or implement the BodyTag interface. So the container will not give a call to the doAfterBody() method of this object.
This method is just a user defined method for this class. So unless explicitly called by some other member of this class, it will never be called.
Hope that answers your question.
 
Goan Balchao
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See, the class dosen't extend BodyTagSupport or implement the BodyTag interface. So the container will not give a call to the doAfterBody() method of this object.
This method is just a user defined method for this class. So unless explicitly called by some other member of this class, it will never be called.
Hope that answers your question.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks hemanth
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I cant accept Hemant answer.. If you extend TagSupport and return EVAL_BODY_INCLUDE it will be treated as IterationTag.
So doAfterBody() will be called.
Ganesh Ram
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"rganniram"-
Welcome to the JavaRanch!
Please adjust your displayed name to meet the JavaRanch Naming Policy.
You can change it here.
Thanks, and again welcome to the JavaRanch!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic