the mock exam at the end of hfsj is of very poor quality. though errata has been published but it does not cover all the errors. i tried searching the forum and i found some links which also deal with the errors. combining with those links, errata and whatever i shall be compiling here it would be helpful for those who are preparing for the web component certification.
QUESTION NO. 19
please find the question below :
A Classic tag handler exists in legacy code. The author wrote a handler that evaluates its tag body a hundred times, to be used in testing other tags that produce random content.
Given:
06. public class HundredTimesTag extends TagSupport {
07. private int iterationCount;
08. public int doTag() throws JspException {
09. iterationCount = 0;
10. return EVAL_BODY_INCLUDE;
11. }
12.
13. public int doAfterBody() throws JspException {
14. if(iterationCount < 100){
15. iterationCount++;
16. return EVAL_BODY_AGAIN;
17. }else{
18. return SKIP_BODY;
19. }
20. }
21. }
What is incorrect about the code?
A. Tag handlers are not thread safe, so the iterationCount can become out of sync if multiple users are reaching the page at the same time.
B. The doAfterBody method is never being called because it is not part of the tag handler lifecycle. The developer should have extended the IterationTagSupport class to include this method in the lifecycle.
C. The doTag method should be doStartTag. As written, the default doStartTag of TagSupport is called which simply returns SKIP_BODY, causing doAfterBody to never be called.
D. When doAfterBody returns EVAL_BODY_AGAIN the doTag method is called again. The doTag method resets iterationCount to 0, resulting in an infinite loop and java.lang.OutOfMemoryError is thrown
i never understood the question. i do understand all the options but the question asks WHAT IS INCORRECT ABOUT THE CODE. and the correct answer it says is C. i think it should be WHAT IS CORRECT ABOUT THE CODE ?
QUESTION NO. 11
please consider the following question as copied from the hfsj book :
Given these fragments from within a single tag in a
Java EE DD:
343. <web-resource-collection>
344. <web-resource-name>Recipes</web-resource-name>
345. <url-pattern>/Beer/Update/*</url-pattern>
346. <http-method>POST</http-method>
347. </web-resource-collection>
...
367. <auth-constraint>
368. <role-name>Member</role-name>
369. </auth-constraint>
...
385. <user-data-constraint>
386. <transport-guarantee>CONFIDENTIAL</transport-guarantee>
387. </user-data-constraint>
Which are true? (Choose all that apply.)
A. A Java EE DD can contain a single tag in which all of these tags can legally co-exist.
B. It is valid for more instances of <auth-constraint> to exist within the single tag described above.
C. It is valid for more instances of <user-data-constraint>
to exist within the single tag described above.
D. It is valid for more instances of <url-pattern> to exist within the <web-resource-collection> tag described above.
E. It is valid for other tags of the same type as the single encasing tag described above to have the same <url-pattern> as the tag above.
F. This tag implies that authorization, authentication, and data integrity security features are all declared for the web application.
the book says option A, B, D, E, F as the correct answers.
while i understood optin A D and E i had doubt about B and F. lets come to option F first. i made a sample program without <login-config> element but WITH <security-constraint> element. when i tried to access constrained resource it gave me 403 access denied error. option f says that the above xml snippet(in the question) declared authenticatin, authorisation and data integrity. while authorisation and data integrity are undersood , it is not true for authentication. we cant predict whether it has declared authentication . it is true that for before authorisation , authentication has to happen and by 403 error we know that the user needs to be authenticated but the exact elements are not declared in the xml file.
option B is wrong unless i misinterpreted the question. i put more than 1 auth-constraint tags inside <Security-constraint> and the web.xml gave error. so in my opinion option B and option f should be rules out unless somebody interprets quesiton in a way that they are true. please respond if somebody else had doubt in the same question ?