You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Sam Joseph <ga...@yha.att.ne.jp> on 2001/08/08 04:18:08 UTC

Re: JSP include and calling servlets: Error: Writer is already being used for this request

Following up to my earlier post.  I've now downloaded 3.2.3 and am getting the same error as with 3.2

I had looked into the tomcat code underlying the error and it seems that the OutputStream is being
requested from the HttpServletResponse more than once.  Once by the servlet that is created to support the
JSP and once by my own servlet.

I'd happily not call the getOutputStream() method in my own servlet, but if I don't how can I send the
output of the servlet to the JSP servlet it is embedded in?

Thanks in advance.

CHEERS> SAM

Sam Joseph wrote:

> Hi,
>
> I've been trying to use JSP to call servlets like this:
>
> <jsp:include page="/servlet/NewsServlet?news_id=980" flush="true"/>
>
> The jsp include successfully initializes the servlet, however, I get the
> error appended below.
>
> I'm using tomcat 3.2.  I'm downloading 3.2.3 to try that out, but I
> wondered if anyone else had the same problem.
>
> Thanks in advance
>
> CHEERS> SAM
>
> Error thrown during news:
> java.lang.IllegalStateException: Writer is already being used for this
> request
>         at
> org.apache.tomcat.facade.HttpServletResponseFacade.getOutputStream(HttpServletResponseFacade.java:158)
>
>         at
> com.neurogrid.prime.NewsServlet.handleRequest(com/neurogrid/prime/New
> sServlet.java:177)
>         at
> com.neurogrid.prime.NewsServlet.doPost(com/neurogrid/prime/NewsServle
> t.java:146)
>         at
> com.neurogrid.prime.NewsServlet.doGet(com/neurogrid/prime/NewsServlet
> .java:112)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>         at
> org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:4
> 04)
>         at org.apache.tomcat.core.Handler.service(Handler.java:286)
>         at
> org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372
> )
>         at
> org.apache.tomcat.facade.RequestDispatcherImpl.include(RequestDispatc
> herImpl.java:345)
>         at
> org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.jav
> a:414)
>         at
> jsp.n_00025ws_00033._0002fjsp_0002fnews_00033_0002fnews_00033_0002ejs
> pnews3_jsp_0._jspService(_0002fjsp_0002fnews_00033_0002fnews_00033_0002ejspnews3
>
> _jsp_0.java:63)
>         at
> org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>         at
> org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspSer
> vlet.java:177)
>         at
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
> 18)
>         at
> org.apache.jasper.servlet.JspServlet.service(JspServlet.java:391)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>         at
> org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:4
> 04)
>         at org.apache.tomcat.core.Handler.service(Handler.java:286)
>         at
> org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372
> )
>         at
> org.apache.tomcat.core.ContextManager.internalService(ContextManager.
> java:797)
>         at
> org.apache.tomcat.core.ContextManager.service(ContextManager.java:743
> )
>         at
> org.apache.tomcat.service.http.HttpConnectionHandler.processConnectio
> n(HttpConnectionHandler.java:210)
>         at
> org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:
> 416)
>         at
> org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java
> :498)
>         at java.lang.Thread.run(Thread.java:484)


Re: JSP include and calling servlets: Error: Writer is already being used for this request

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Wed, 8 Aug 2001, Sam Joseph wrote:

> Following up to my earlier post.  I've now downloaded 3.2.3 and am getting the same error as with 3.2
> 
> I had looked into the tomcat code underlying the error and it seems that the OutputStream is being
> requested from the HttpServletResponse more than once.  Once by the servlet that is created to support the
> JSP and once by my own servlet.
> 
> I'd happily not call the getOutputStream() method in my own servlet, but if I don't how can I send the
> output of the servlet to the JSP servlet it is embedded in?
> 

The servlet spec says that, for any given response, you must use *either*
response.getOutputStream() *or* response.getWriter().  Because JSP uses
response.getWriter(), that means you should do the same in your servlet.

The only time you get IllegalStateException is when *both* are called on
the same response.

> Thanks in advance.
> 
> CHEERS> SAM
> 

Craig McClanahan