You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Lance Smith <ls...@emergent-netsolutions.com> on 2002/03/05 18:32:51 UTC

getOutputStream() has already been called for this response

Help,
Why would this code:
public class Controller extends HttpServlet {
    ...

    protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
    throws ServletException, java.io.IOException {
        HTMLTagHelper tagHlpr = new HTMLTagHelper( getServletContext() );
    include(request, response, "/Include/stdHead.inc");
//        out.println("<html>");
//        out.println("<head>");
        java.io.PrintWriter out = response.getWriter();
        out.println("<title>Servlet</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<p>pathInfo=>" + request.getPathInfo());
        out.println("<p>pathTrans=>" + request.getPathTranslated());
        out.println("<p>requestURI=>" + request.getRequestURI() );
        out.println("<p>RealPath=>" +
getServletContext().getRealPath("." ));
        out.println("<p>ServletPath=>" + request.getServletPath());
        out.println("<p>QueryString=>" + request.getQueryString());
        out.println("<p>ContextPath=>" + request.getContextPath());

        out.println("</body>");
        out.println("</html>");
        out.close();
    }
  protected void include( HttpServletRequest request,
			   HttpServletResponse response,
			   String page )
	  throws ServletException, java.io.IOException {
      RequestDispatcher dispatcher = request.getRequestDispatcher( page );
      dispatcher.include( request, response );
  } // protected void dispatch
  ...
}

Throws this error:
java.lang.IllegalStateException: getOutputStream() has already been called
for this response
	at
org.apache.catalina.connector.ResponseBase.getWriter(ResponseBase.java:755)
	at
org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:1
65)
	at Controller.processRequest(Controller.java:54)
	at Controller.doPost(Controller.java:88)
      ...

If I remove the call to include and uncomment the lines everything works
fine.
Tomcat 4.0.2
Thanks in advance for thoughts suggestion whatever I really need to mix
includes
with the PrintWriter in this application.

Lance



--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>


Re: getOutputStream() has already been called for this response

Posted by Toru Watanabe <t-...@du.jp.nec.com>.
Hi Lance,

You should get writer before include.

regards,
Watanabe

--
To unsubscribe:   <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>