• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Eduardo Mock Exam : No. 24

 
Michael Santosa
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given a tag handler defined with <bodycontent>JSP</bodycontent> which implements TagSupport and ONLY overrides doAfterBody with the following lines:
public int doAfterBody() throws JspException {
try { pageContext.getOut().print(� how are you? �);}catch(IOException e) {}
return SKIP_BODY;
}
What will be the result of a jsp with the following part?
<prefix:sufix>
<i>Hello</i>
</prefix:sufix>
1) The jsp page will print: Hello
2) The jsp page will print: Hello how are you?
3) The jsp page will print: how are you? Hello
4) The jsp won't print anything.
The answer is :
4) The jsp won't print anything.
TagSupport.doStartTag by default returns SKIP_BODY and as it is not overriden the body is ignored.
As I remembered that TagSupport doesn't
have doAfterBody, we have to implement
BodyTagSupport... please correct me if
I am wrong.
And what is the different between
JSP 1.1 & JSP 1.2 ?
It seems like I studied JSP 1.1 a lot,
and there are some big different..
Thx..
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since TagSupport does not call doAfterBody method the JSP will print blank since doStartTag returns SKIP_BODY by default and there is no doEndTag method also defined ..the method DoAfterBody is just like any other method which has no role to play during the time the tag gets executed..

Originally posted by Michael Santosa:
Given a tag handler defined with <bodycontent>JSP</bodycontent> which implements TagSupport and ONLY overrides doAfterBody with the following lines:
public int doAfterBody() throws JspException {
try { pageContext.getOut().print(� how are you? �);}catch(IOException e) {}
return SKIP_BODY;
}
What will be the result of a jsp with the following part?
<prefix:sufix>
<i>Hello</i>
</prefix:sufix>
1) The jsp page will print: Hello
2) The jsp page will print: Hello how are you?
3) The jsp page will print: how are you? Hello
4) The jsp won't print anything.
The answer is :
4) The jsp won't print anything.
TagSupport.doStartTag by default returns SKIP_BODY and as it is not overriden the body is ignored.
As I remembered that TagSupport doesn't
have doAfterBody, we have to implement
BodyTagSupport... please correct me if
I am wrong.
And what is the different between
JSP 1.1 & JSP 1.2 ?
It seems like I studied JSP 1.1 a lot,
and there are some big different..
Thx..
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I remembered that TagSupport doesn't
have doAfterBody, we have to implement
BodyTagSupport... please correct me if
I am wrong.

That is not true.
TagSupport does have doAfterBody. doAfterBody is defined in IterationTag interface and TagSupport implements InterationTag interface. Hence it must have a default implementation for the doAfterBody method, which returns a SKIP_BODY.
And what is the different between
JSP 1.1 & JSP 1.2 ?
It seems like I studied JSP 1.1 a lot,
and there are some big different

Yes, there are bid differences. You do have to follow JSP.1.2 version on this.
regds.
- madhav
 
Asher Tarnopolski
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i didn't get this one at all.
i have tried to run it, and if i use TagSupport i get a compilation error. It runs with BodyTagSupport only and outputs "Hello"...How come?
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i use TagSupport i get a compilation error
When you used TagSupport, what did you return from doStartTag() and what was the compilation error?
- madhav
[ May 01, 2002: Message edited by: Madhav Lakkapragada ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic