tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hans Bergsten <>
Subject Re: Error With RequestDispatcher to Jsp ?
Date Mon, 24 Apr 2000 19:19:22 GMT
David Qian wrote:
> Hi, Hans:
> Thank you very much for your help.  After I made some change as you
> suggested, it works now.
> But, I have come across another problem. I used RequestDispatcher to forward
> from a servlet to a error.jsp page.
> RequestDispatcher rd;
> rd = this.getServletContext().getRequestDispatcher("/jsp/error.jsp");
> rd.forward(request, response);
> More codes after these statements, include :
> StringBuffer buffer = new StringBuffer();
> response.setContentType("text/html");
> PrintWriter out = response.getWriter();
> out.println("<html>");
> out.println("<head><title>SimpleDataAccess</title></head>");
> out.println("<body>");
> out.println(testing + " \n");
> out.println(buffer.toString());
> out.println("</body></html>");
> out.close();
> The information after RequestDispatcher continues to be printed out in the
> error.jsp page.  If the servlet is forwarded to another servlet, there is no
> such a problem.
> Thank you all in advance !

Most likely the servlet you forward calls close() on the writer (so the extra
println() calls in the original servlet are ignored), but the servlet generated
from the JSP page doesn't. It sounds like it is a bug in the JSP container, but
I'm not sure exactly how the expected behavior is described in the spec.

Anyway, when you return from a forward, you should never try to produce more
output; just return from the doGet/Post() method. If you need to produce output
from the original servlet as well as another servlet/JSP, use include instead
of forward. See the Servlet 2.2 spec for details.

Hans Bergsten
Gefion Software

View raw message