Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clarification needed

 
Aleksander Zielinski
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(1) In fact both are correct - there is only an esoteric distinction and this is about word play. For example, do you consider a Web application as "a single JAR file assembly" or "a distribution of that JAR file on a server"? In fact it could be either or both: an "application" can either represent a piece of software which exists (e.g. Microsoft Word is an application), or it can mean something running dynamically on a particular machine (e.g. my Word application contains different configuration data to your Word application). For answer A (which is the one I thought would be correct), we're talking about a single instance of that application running on a server. For your answer E, you're talking about a Web application assembly (regardless of its deployment). Your answer is perhaps more exact, but as I say, the lack of clarity in the wording means A could also be correct.

(2) Again, probably a lack of clarity in the question. If they had said "associate the event with the appropriate listener interface installed in the container" there would be no doubt that it must be HttpSessionAttributeListener. You are correct that HttpSessionBindingListener will work.

(3) You are probably correct in assuming they have used "request" rather than "response" as a mistake - although this is a poor question because in fact they could have declared:as the method header, and everything would be okay! Well, perhaps this is daft, but it isn't explicit and therefore is unclear.

As I'm sure you know, as a side point, invoking forward() causes all content currently in the response to be lost. They are correct in their answer; the spec. states:
Before the forward method of the RequestDispatcher interface returns, the response content must be sent and committed, and closed by the servlet container
If your Tomcat is not displaying this behaviour, it is a bug in Tomcat.

(4) I agree with you - there is no reason why this couldn't be implemented as a SimpleTag. In fact, I remember this same question coming up a few weeks ago on this very forum, and we decided that D was just wrong - the only guarantee is that it must implement JspTag (and more specifically either Tag or SimpleTag).

Oh, and while it's nice to appreciate TLD syntax, I don't believe it is an exam objective to learn, or even recognise, any of it (unlike the DD which must be learnt in part). Please correct me if I'm wrong.

(5) I agree that D is correct... E is wrong because the page directive setting takes precedence over the setting in the DD (whatever that setting is). Are you sure you read the errata correctly? If so, it looks like an errata to the errata is required!

(6) I agree that answers A and D are correct, for the reasons you give. The numerical indexing example is the 'classic' one - List[0] is correct, but List.0 is illegal. Also, why is C incorrect? I don't have a container at hand to try this, but I do seem to remember obtaining PropertyExceptions (a runtime exception) from my Tomcat installation when a property couldn't be referenced. The JSP 2.0 spec (section 2.3.4) states:
Otherwise (a JavaBeans object), coerce value-b to String
If value-b is a readable property of value-a, as per the JavaBeans specification:
  • If getter throws an exception: error
  • Otherwise: return result of getter call
  • Otherwise: error.
    and it states earlier that:
    An error is an exception thrown (to be handled by the standard JSP machinery).
    As I read this, if a JavaBeans property cannot be resolved, the container is entitled to raise an exception which might then be propagated to the calling page. So I think C could be correct as well - does anyone think differently?


    Good luck in the exam!
    [ May 11, 2006: Message edited by: Charles Lyons ]
     
    Aleksander Zielinski
    Ranch Hand
    Posts: 127
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you very much Charles for your prompt answer and explanation. You always have a justification to your answers and they have a high value. As I said before, and I'll gladly say it again, if I didn't have to pass my exam now, I would definately buy your book and I reccomend to anyone that is going to pass the exam to do so. You just know your job!

    As for the errata to errata

    {336} Question #6;
    The answer should be E, not D.

    I've also found a couple of minor mistakes, no casting when getting a String through getAttribute and the like that are no in th errata.

    Originally posted by Charles Lyons:


    As I'm sure you know, as a side point, invoking forward() causes all content currently in the response to be lost. They are correct in their answer; the spec. states:

    Before the forward method of the RequestDispatcher interface returns, the response content must be sent and committed, and closed by the servlet container

    If your Tomcat is not displaying this behaviour, it is a bug in Tomcat.


    Yes, then that is bug in Tomcat, because even if I manually add out.flush() and out.close() in the second servlet like this:

    PrintWriter out = request.getWriter();
    out.println("<br>Page 2");
    out.flush();
    out.close();

    Nothing happens, no exception is thrown.

    [ May 11, 2006: Message edited by: Aleksander Zielinski ]
    [ May 11, 2006: Message edited by: Aleksander Zielinski ]
     
    Charles Lyons
    Author
    Ranch Hand
    Posts: 836
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I would definately buy your book and I [recommend] to anyone that is going to pass the exam to do so. You just know your job!
    Thanks - recommendations to others are always welcome! The book is full of handy reference material though, like DTD and TLD schemas in diagram form and custom tag lifecycles as flow charts, as well as important API details which are bullet-pointed and indexed. So if you find you get stuck on the job, you'll know where to look! Also there are a couple of additional chapters on new J2EE 5 Web material (everything but Faces which is just too big to discuss sensibly) which is non-examinable in SCWCD 1.4.

    I've also found a couple of minor mistakes, no casting when getting a String through getAttribute and the like that are no[t] in th[e] errata.
    Those things can be really easy to miss if you've got a publisher breathing down your neck to get the book out ASAP... rushing is something I sorely tried to avoid and as a result have spend about 6 months having the text proof-read in about 4 phases to eliminate (I hope) all the problems! Might I suggest adding those mistakes to the errata for the book though, as a reprint would surely include them.


    By the way, did you agree with my reasoning that C might be correct as an answer to (6)?
    [ May 11, 2006: Message edited by: Charles Lyons ]
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic