The forward method should be used to give another resource responsibility for replying to the user. If you have already accessed a ServletOutputStream or PrintWriter object within the servlet, you cannot use this method; doing so throws an IllegalStateException.
you usually do not call a outputstream in a jsp. the jsp has an implicit Jspwriter object. and the question is related to that i believe. it states in the errata that both write and flush methods will lead to a state exception. so if you use a out.write() or out.flush() you get a illegalstate exception.
if who i am is what i have, and what i have is lost, then who am i?<br /> <br />SCJP 5.0<br />SCWCD 1.4<br />SCBCD preparing
Joined: Sep 26, 2006
Check the errata page of HFS in oreilly.com. I remember there is a comment related to this question.
Thanks. It say says:
 Answer to question 1; Option C should also be checked.
you usually do not call a outputstream in a jsp. the jsp has an implicit Jspwriter object. and the question is related to that i believe.
Were you under the impression that the following quote in my original post was just a brief synopsis of the actual question?
But in HF Servlets & JSP, on p. 209, there is this mock exam question:
1) When using a RequestDispatcher, the use of which methods can often lead to an IllegalStateException? (Choose all that apply.)
A. read B. flush C. write D. getOutputStream E. getResourceAsStream
it states in the errata that both write and flush methods will lead to a state exception. so if you use a out.write() or out.flush() you get a illegal state exception.
Using the code:
ServletOutputStream out = response.getOutputStream();
is a preliminary step to using:
My tests (using Tomcat) show that just calling getOutputStream() is enough to cause an IllegalStateException, so I'm wondering if that is generally true or whether Tomcat is out of spec? The java docs say "accessing a ServletOutputStream" will cause the exception. I originally interpreted that to mean calling getOutputStream(), and my tests confirmed that getOutputStream() does cause an IllegalStateException. But maybe "accessing a ServletOutputStream" means calling one of its methods. [ October 15, 2006: Message edited by: sven studde ]