Qian Weichun wrote:

> The bug lies here:
>         I forward a request in my servlet.
>         After I commit the output, I perform the forwarding.
>         Tomcat doesn't act conforming to the servlet 2.2 specification,
> which specifies that it should throw the IllegalStateException.
>         Peek the source:
>         public void doGet(HttpServletRequest request,HttpServletResponse response) 
>throws IOException,ServletException {
>                 response.setContentType("text/html;charset=gb2312");
>                 PrintWriter out = response.getWriter();
>                 out.println("<html>");
>                 out.println("<head>");
>                 out.println("<title>Forward A Request</title>");
>                 out.println("</head>");
>                 out.println("<body>");
>                 out.println("<h1>Just A Test!</h1>");
>                 out.println("</body>");
>                 out.println("</html>");
>                 out.flush();
>                 
>request.getRequestDispatcher("/forwarded.jsp").forward(request,response);
>         }
>

Qian,

If Tomcat 3.2 were an implementation of the Servlet 2.3 specification, this would 
indeed be a spec violation, because the
2.3 spec specifically states that flushing the output stream returned by 
response.getOutputStream(), or the PrintWriter
returned by response.getWriter(), will cause the response to be committed.

In a servlet 2.2 environment, however, it is not defined whether or not a flush() call 
on the output stream or writer causes
the response to be committed.  Therefore, Tomcat's behavior (while perhaps unexpected) 
is within the bounds of acceptable
behavior.

If you want to ensure that the response has been committed, no matter what version of 
the servlet spec your container
implements, call response.flushBuffer() instead of out.flush().

Craig McClanahan



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to