Hello,
I'm passing my exam on tommorow morning. I've collected some questions I need clarification on. Would be very appreciated for help.
Please answer only if you can justify your answer. Thank you very much for your time and help.
Ok, let's start.
1) A parameter is defined in a <context-param> element of the deployment descriptor for a web application. Which of the following statements
is correct? Select 1 correct option.
A. It is accessible to all the
servlets of the webapp.
B. It is accessible to all the servlets of all the webapps of the container.
C. It is accessible only to the servlet it is defined for.
D. It is accessible only in the init() method of the servlet.
E. None of the above is correct.
The answer is A. - "It is accessible to all the servlets of the webapp." My answer is E. - "None of the above is correct." In case of distributed application, we have different ServletContext for each JVM, so Servlets in second JVM will not have access to context param of ServletContext in first JVM. Am I wrong?
2) Associate the event with appropriate listener interface.
The event ---> An attribute is replaced in the session.
Avaiable Listeners ----> HttpSessionActivationListener, HttpSessionListener, HttpSessionBindingListener, NONE.
There correct answer for this event was "NONE". Though the most appropriate would be HttpSessionAttributeListener which is not avaiable as an answer, I decided to choose HttpSessionBindingListener. When the attribute is replaced in the session, the old one may implement HttpSessionBindingListener and therefore it's valueUnbound() method will be invoked. What do you think?
3) Consider the following code snippets. What will be displayed on the browser when a GET request is sent to FirstServlet assuming that the buffer is large enough to hold all the data before sending the data to the client?
In the doGet() of FirstServlet:
PrintWriter out = response.getWriter();
out.println("<html><body>Page 1");
RequestDispatcher rd = request.getRequestDispatcher("NextServlet");
rd.forward(request, response);
out.println("<br>Page 3</body></html>");// COMMENT
In the doGet() of SecondServlet:
PrintWriter out = request.getWriter();
out.println("<br>Page 2");
A. Only Page1 and Page3
B. Only Page2
c. Page1, Page2, and Page3
D.
IllegalStateException at Runtime.
E. Compilation Error.
The answer is D. - "IllegalStateException at Runtime". Here's the provided justification:
Calling forward() means that the request processing is delegated to the callee resource permanently. So, although the control does return to the caller resource [because rd.forward() is just a regular method call], the caller resource cannot generate any output after the call to forward(). In this case, FirstServlet is trying to send output to the client after calling forward() and so an IllegalStateException will be thrown. They are talking about "// COMMENT" line.
First thing, in the SecondServlet ther's invocation of getWriter() method on request object, so I choosed E. - "Compilation error.". Regardless of that (assume that was a mistake and there should be response object), in my
Tomcat container there's no IllegalStateException thrown. Everything works fine and I get the "Page2" result. Futhermore, I can even add out.write("XXX"); or out.flush(); after the "// COMMENT" line and it's ok.
4). Consider the following description of a tag in a TLD:
<tag>
<name>SmilyTag</name>
<tag-class>com.enthuware.ctags.SmilyTag</tag-class>
<description>
Replaces emoticons such as

,

, and

with images.
</description>
<body-content>tagdependent</body-content>
<attribute>
<name>name</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
Which of the following statements regarding the above tag are correct?
A. It is an empty tag.
B. It may be used as an empty tag.
C. It must have a body.
D. It must implement BodyTag interface.
E. It may take an attribute named 'name'. But if present, its value must be dynamic.
One of the answers is D. - "It must implement BodyTag interface". I don't think it is mandatory, if it doesn't implement BodyTag interface, we just won't have access to contents of the body of the tag. The tag still works, there's no error. If the question was something like: "What is appropraite for this tag?" and the answer was like "To implement BodyTag interface." then ok, but it's not a must in my opinion. What is yours?
5). Question 6 page 336 HFSJ.
Given:
<%@ page isELIgnored="true" %>
What is the effect?
A. Nothing, this page directive is NOT defined.
B. The directive turns off the evaluation of EL code by the
JSP container in all of the web app's JSP's.
C. The JSP containing this directive should be treated by the JSP container as a well-formed XML file.
D. The JSP containing this directive should NOT have any EL code evaluated by the JSP container.
E. This page directive will only turn off the EL evaluation if the DD declares a <el-ignored>true</el-ignored> element with a URL
pattern that includes this JSP.
I choosed D, but according to errata, the answer should be E not D. I don't think E should be the correct answer.
6). Question 17 page 432 HFSJ.
Which about EL access operators are true?
A. Anywhere the .(dot) operator is used, the [] could be used instead.
B. Anywhere the [] operatoe is used, the .(dot) could be used instead.
C. If the .(dot) operator is used to access a bean property but the property doesn't exist, then a runtime exception is thrown.
D. There are some situations where the .(dot) operator must be used and other situations where the [] operator must be used.
According to errata only answer A. is correct. In my container (Tomcat) I'm getting an exception when trying to use .(dot) operator on a bean and this bean's property doesn't exit. Another thing is that in my opinion answer D is also correct. Justification to this answer is as follows: "Option D is incorrect because the .(dot) operator can always be converted to the [] operator.". YES, this is right, but the [] operator can't always be converted to .(dot) operator. List[0] can't be expressed as List.0 , we must use [] operator, in my opinion answer D. is correct. Are on the exam so ambiguous questions too?
That's all for now, but I'll be doing final mock exam from HFSJ in a couple of hours, so I might add new questions

Thank you once more for you thoughts on questions.