If the aTagWithBody handler extends from TagSupport and returns BodyTag.EVAL_BODY_BUFFERED from doStartTag(), what will the above page print?
A) Tag Handler will not compile
B) An Exception at request time
C) "Body Content" will NOT be printed
D) "Body Content" will be printed
E) None of these
I think it should be A because the constant BodyTag.EVAL_BODY_BUFFERED is not available in TagSupport (see API) but the answer given is:
"It will compile because the compiler only checks whether the doStartTag() is returning an int or not. It does not check whether the int value is valid or not."
"At request time, the container validates the return value of the doStartTag() methods. In this case, since the Tag handler extends from TagSupport, it does not implement BodyTag interface and so it cannot return BodyTag.EVAL_BODY_BUFFERED from the doStartTag() method. The behavior of the container, in such as case, is undefined. One container may cause a ServletException to be thrown from the JSP page and another may just ignore it.
However, the tag can be coded to return BodyTag.EVAL_BODY_BUFFERED without any compile time error because the compiler does not have any knowledge of what this tag is allowed to return."
This explanation seems to be saying that the compiler will not check that this constant exists! Is this correct? I have my exam in 1 hour.....
I would say you can get such a question on the exam. Some exam question are really really tricky. In my SCWCD exam I got one question where the question asked for 2 correct answers but I thought 3 answers were correct. It took me 10 minutes to figure out that single question...