Best Regards,<br />Balaji Natarajan<br /> <br />SCJP 1.5 100%<br />SCWCD 1.5 92%<br />SCBCD (In Progress)
Originally posted by MyMyselfAndI:
Question 14
It is true that JEE container must support SSL?
SCJP 1.4 (81%)<br />SCWCD 5 (95%)
SCJP 1.4 (81%)<br />SCWCD 5 (95%)
Q33:
What is generally true about the lifecycle of a servlet? (Choose all that apply.)
X A. You should NOT write a constructor for a servlet.
B. You should NOT override a servlet�s init() method.
C. You should NOT override a servlet�s doGet() method.
D. You should NOT override a servlet�s doPost() method.
X E. You should NOT override a servlet�s service() method.
F. You should NOT override a servlet�s destroy() method.
I think E is not correct.. If you call super(), you can do some general stuff in there.
And if the 'servlet' is not an HttpServlet, but a GenericServlet, it even has to!
SCJP 1.4 (81%)<br />SCWCD 5 (95%)
Answer according to HF is B: - because os.flush() wasn�t called, the uncommitted output (123), is cleared, and forward is invoked without exception. If os.flush() had been called before forward, an IllegalStateException would have been thrown.
This is not true. The above code will always cause an IllegalArgumentException, flushed or not. The implementation class of the JSP page will create a PageContext object, which in turn will call getWriter() on the response object (to set its out property). Because the response object already called getOutputStream(), it will throw an exception.
Originally posted by Eurig Jones:
Even if you call getWriter() in the servlet instead of getOutputStream() it throws an IllegalStateException.
Originally posted by Eurig Jones:
I also tried getWriter() and then getOutputStream() alone in a Servlet without request dispatch. Throws an IllegalStateException from Servlet.
But If getWriter is called twice in the same servlet (or if getOutputStream is called twice), it DOESN'T throw an IllegalStateException. Why is this?
Originally posted by Eurig Jones:
what is happening when the RequestDispatcher forwards? is it flushing? It doesn't mention this in the API.![]()
SCJP 1.4 (81%)<br />SCWCD 5 (95%)
SCJP 1.4 (81%)<br />SCWCD 5 (95%)
I don't
Could you copy/paste your code and the exception?
Nope, only the forward() method does; include() doesn't.Originally posted by Eurig Jones:
- RequestDispatcher clears the buffer as you mentioned.
Right. Even if you don't write anything to/in the stream/JSP, just making the call getOutputStream() in a JSP will throw an exception.Originally posted by Eurig Jones:
- You cannot mix the use of getWriter() and getOutputStream() on the same Response object
- If you call getOutputStream() in a JSP even if it only has 1 character in it, it'll throw an IllegalStateException because it's allready pinched the PrintWriter
Right.Originally posted by Eurig Jones:
- But you CAN use getWriter() in the Servlet and forward it on to the JSP.
SCJP 1.4 (81%)<br />SCWCD 5 (95%)
no wonder he is so sad, he hasn't seen this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|