Hello.
   Number one. That happens, if you try to "sendRedirect" in the body of the
JSP. However the JSP is parsed to a Servlet, and it writes the JSP's body to
the output stream. The problem is, that when the sendRedirect is found later
in the body the output of the Servlet can become quite large, and the
servlet's output is flushed, because the buffer is overrun.

   Solution One (not tested): at the start of the JSP put: <%@ page
buffer="65kb" %>
     That is temporary solution. If you try to redirect after this buffer is
full, you will get the exception again.

   Solution Two (my favorite): At the start of the JSP do whatever work is
needed. That way normally you will not have sent any data and there will
still be possibility to "sendRedirect".

   Solution Three (my current): Use the JSP to display data only. All work
should be done in a Servlet, that does not write anything, but only does
work, and then "sendRedirect"s to the JSP. This is quite flexible.

   Solution Four (ugly, but works): If your JSP ALWAYS redirects to the
other location (no ifs, no cases), and your JSP produces HTML, than you can
always put in the html a <META> tag to make the redirect.
    <HEAD>
      <META HTTP-EQUIV="REFRESH" CONTENT="0; URL=/MySecondJspLocation.jsp">
    </HEAD>

   You may think of more solutions, but it IS normal to receive that
exception. You can not expect Orion to buffer ALL the output of a jsp,
right?

   Lachezar.



> Hello all,
>
> I have a JSP, that processes a form and is attempting to create a record
in my database via CMP EJB (Person). After my form
> has been processed and the PersonHome.create() methods has succeeded
(record has been created), the page tries to
> redirect to another JSP. But this doesn't work; instead i receive an
exception:
>
> java.lang.IllegalStateException: Response has already been committed, be
sure not to write to the OutputStream or to trigger a
> commit due to any other action before calling this method.
>  at com.evermind[Orion/1.5.2 (build
10460)].server.http.EvermindHttpServletResponse.sendRedirect(Unknown Source)
>  at /department.jsp._jspService(/department.jsp.java:54) (JSP page line
19)
>  at com.orionserver[Orion/1.5.2 (build
10460)].http.OrionHttpJspPage.service(Unknown Source)
>  at com.evermind[Orion/1.5.2 (build 10460)]._ah._rad(Unknown Source)
>  at com.evermind[Orion/1.5.2 (build
10460)].server.http.JSPServlet.service(Unknown Source)
>  at com.evermind[Orion/1.5.2 (build 10460)]._cxb._abe(Unknown Source)
>  at com.evermind[Orion/1.5.2 (build 10460)]._cxb._uec(Unknown Source)
>  at com.evermind[Orion/1.5.2 (build 10460)]._io._twc(Unknown Source)
>  at com.evermind[Orion/1.5.2 (build 10460)]._io._gc(Unknown Source)
>  at com.evermind[Orion/1.5.2 (build 10460)]._if.run(Unknown Source)
>
> without PersonHome.create() or response.sendRedirect() everything works
fine (it works fine with either, but not with both).
> What is going on? What am I doing wrong?


Reply via email to