Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WAS 3.5.4 ERROR: Cannot forward. Writer or Stream already obtained.

3 views
Skip to first unread message

Catherine

unread,
Sep 19, 2001, 2:59:40 PM9/19/01
to
My servlets have been running on WAS 3.5 successfully for quite some time. I
upgraded it to WAS 3.5.4 today. And the servlet suddenly don't work. The
error message is:

Rot Error -1: ERROR: Cannot forward. Writer or Stream already obtained.

java.lang.IllegalStateException: ERROR: Cannot forward. Writer or Stream
already obtained.
at java.lang.RuntimeException.<init>(RuntimeException.java:49)
at
java.lang.IllegalStateException.<init>(IllegalStateException.java:47)
at
com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.handleOutputStreamPrin
terWriterObtained(WebAppRequestDispatcher.java:595)
at
com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.forward(WebAppRequestD
ispatcher.java:112)
at MyServlet.performTask(MyServlet.java:120)
at MyServlet.doGet(MyServlet.java:27)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
..........

The processing flow of the http request is:
request from browser -> main servlet -> forward to a generic
jsp -> include another servlet -> forward to final jsp
The error message occurred when the last servlet tries to forward to the
final jsp.

I wonder why it is okay with version 3.5 but failed with 3.5.4.

Sincerely,
Catherine

Rob Winston

unread,
Sep 19, 2001, 3:15:54 PM9/19/01
to
What you're doing is in violation of the spec (once something does a
"getWriter()", forward is forbidden), although certain things can be done
when JSPs are involved if the buffer has not been flushed. If WAS was
letting you do it, it was a hole that one of the fixpacks has apparently
plugged.

"Catherine" <li...@arkayusa.com> wrote in message
news:9oaq6v$usi$1...@news.boulder.ibm.com...

Alex Matthews

unread,
Sep 19, 2001, 3:19:09 PM9/19/01
to
This hole was indeed plugged, some time back - 3.5.2 maybe?

Alex.

Catherine

unread,
Sep 19, 2001, 5:13:39 PM9/19/01
to
Thanks for the feedback.

The point is, I did not call the getWriter() method at all. What I did are:
1) In the main servlet:
1a) setContentType, setHeader;
1b)
getServletConfig().getServletContext().getRequestDispatcher("result.jsp").fo
rward(request, response);
2) In the result.jsp, there are a fixed header and footer, and:
<jsp:include page="SecondServlet" />
3) In SecondServlet:

getServletConfig().getServletContext().getRequestDispatcher("response.jsp").
forward(request, response);

I did not write any response in the servlets. All response html were written
by jsp.
No getWriter() issued, no flush buffer performed.

Is there anything wrong with my processing sequence described above?

"Alex Matthews" <al...@xelacom.com> wrote in message
news:3BA8EFAD...@xelacom.com...

Alex Matthews

unread,
Sep 20, 2001, 3:52:24 AM9/20/01
to
Ah, but you did.

setContentType (and possibly setHeader) write back to the output stream.
See section 5.5 of the servlet 2.2 spec - it's not limited to getWriter.
I'm also not sure you can invoke forward from an included servlet.

Alex.

Ken Hygh

unread,
Sep 20, 2001, 6:06:03 AM9/20/01
to
Alex is right, you cannot invoke forward from an included servlet, only
include.

Ken

santi

unread,
Sep 20, 2001, 6:25:20 AM9/20/01
to
I had the same messages.... try this e-fix PQ49167
Good luck!

Eric B. Farrar

unread,
Sep 20, 2001, 7:47:50 AM9/20/01
to
It wasn't the setting of the headers that committed the response, it was
the <jsp:include ... /> that did it. At the JSP 1.0/1.1 levels
"include"
implicitly flushes the JspWriter, which commits the response.
Setting headers should not commit the response or even cause an iostream
to be acquired.


Eric

Alex Matthews

unread,
Sep 20, 2001, 8:39:22 AM9/20/01
to
Fair enough - I stand corrected.

Alex.

Catherine

unread,
Sep 20, 2001, 9:16:12 AM9/20/01
to
Thanks for the tips. I changed the 2nd forward to include, and the problem
was solved.

Cheers,
Catherine

"Alex Matthews" <al...@xelacom.com> wrote in message

news:3BA9E37A...@xelacom.com...

0 new messages