• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Complile time OR Request time error

 
Poonam Agarwal
Ranch Hand
Posts: 324
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider the following JSP codeEnthuware Mock)

<mylib:MyIterTag>
<%="Hello World"%>
</mylib:MyIterTag>

If the tag handler class for MyIterTag implements IterationTag and returns IterationTag.EVAL_BODY_BUFFERED from doStartTag(), what will be output in the response?

1. Hello World
2. <%="Hello World"%>
3. The tag handler will not compile.
4. The tag handler will compile but throw an exception at request time.
5. No compile-time or run-time erros and nothing will be printed in the output.

Correct answer is 3. I don't think so, becouse compiler checks weather it returns an int value or not. It is valid or not it will check at the request time.

Please correct me If i am getting it wrong.

Thanks
 
Chithra Salam
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MyIterTag implements IterationTag not BodyTag. So I think as EVAL_BODY_BUFFERED is not a field in IterationTag and so taghandler will not compile.

Thanks,
Chithra Salam.
[SCWCD -in progress,SCJP 1.4-85%]
 
Poonam Agarwal
Ranch Hand
Posts: 324
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CHITHRA SALAM wrote:MyIterTag implements IterationTag not BodyTag. So I think as EVAL_BODY_BUFFERED is not a field in IterationTag and so taghandler will not compile.

Thanks,
Chithra Salam.
[SCWCD -in progress,SCJP 1.4-85%]


again, I don't think so, becouse compiler checks weather it returns an int value or not. It is valid or not it will check at the request time. check it by creating a sample .
 
Kamal Tripathi
Ranch Hand
Posts: 86
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Poonam Agarwal wrote:

again, I don't think so, becouse compiler checks weather it returns an int value or not. It is valid or not it will check at the request time. check it by creating a sample .


Chithra is correct here. You are missing the point. What she meant is that EVAL_BODY_BUFFERED has been declared as a field in BodyTag interface and not in IterationTag.

So @ compile time it will fail.

What you say is true that compiler checks whether it returns int value or not but how would it return if it is not declared in the iterface!!!

See JSP 2.0 docs for each interface


http://tomcat.apache.org/tomcat-5.5-doc/jspapi/javax/servlet/jsp/tagext/IterationTag.html

http://tomcat.apache.org/tomcat-5.5-doc/jspapi/javax/servlet/jsp/tagext/BodyTag.html


Compiler takes the value of static fields and replaces them by their values at compilation so in class file you must be seeing an int value but for that it must find the field something like

public static final int EVAL_BODY_BUFFERED = ... ;

which it won't in this case.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic