This seems to be caused by a bug in Tomcat 3.2.1.  I looked at the java
code
generated for my JSP.  It call out.flush() at the end.  I think that's why
the
forward() failed.  I then converted example1.jsp from JSPs to servlets but
I am still getting the same Exception.  Moving my code below from a JSP
to a servlet did not help.  I check the Servlet 2.2 spec and it does not
mention
anything about flushing or committing the output when using
RequestDispatcher.include().  Anyone knows if this bug exists in later
version
of Tomcat also.

On a related note.  I noticed that Tomcat always call out.flush() in the
java
code it generates for JSP.  Isn't that a bug?

Bill

William Au wrote:

> I am running Tomcat 3.2.1.
>
> I am getting the following error.
>
> javax.servlet.ServletException: Cannot forward as OutputStream or Writer
> has already been obtained
>
> My code is quite simple.  The jsp that I am including, example1.jsp,
> does not write anything to the
> output buffer.
>
> <%
> RequestDispatcher rd1 =
>   request.getRequestDispatcher("example1.jsp");
> rd1.include(request, response);
>
> RequestDispatcher rd2 =
>   request.getRequestDispatcher("example2.jsp");
> rd2.forward(request, response);
> %>
>
> The Apache Bug Database, bug #250, said this is fixed in 3.2.  Is there
> something
> wrong with my code?
>
> Bill

Reply via email to