tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Cruikshank <a...@epitonic.com>
Subject Re: IllegalStateException
Date Wed, 29 Dec 1999 21:03:35 GMT
At 05:08 PM 12/29/99 +0800, you wrote:
>I've been getting the following exception message. I can't seem to
>pinpoint the source of the error, please help. I'm using 3.0, not a CVS
>snapshot.
>
>Thanks.

This exception seems to be caused by a call to response.getOutputStream() 
in your Jsp code.  The servlet spec allows the servlet writer to write to 
an OutputStream or a Writer, but not both.  You can retrieve the 
OutputStream without an exception from the response object in a JSP page 
because the JspWriter ("out") does not actually try to get the response's 
Writer until it is actually needed.  The page will invariably throw the 
IllegalStateException below, however, because it always tries to flush the 
output at the end of the page (at which time it tries to get the Writer, 
and the response throws and IllegalStateException because it has already 
given out the OutputStream).

If you have called getOutputStream(), the simple solution is to not call 
getOutputStream() :).  JSP pages are meant to serve HTML (or possibly XML) 
data.  If you need to send binary data, you should use a servlet instead of 
a JSP page.  If you haven't called getOutputStream(), there might be a more 
obscure bug in the Jsp or servlet engine.

This brings up a question for the group.  Since calling getOutputStream() 
could be a common error, shouldn't the getOutputStream() method throw the 
IllegalStateException() (where it can be caught and forwarded to the error 
page) instead of the flush() in the finally clause at the end of the page 
(where it's sure to cause confusion).  This could easily be accomplished by 
having the JspWriterImpl get the writer from the response in its 
constructor (instead of the first time it's needed).  I'm not quite sure 
what purpose this delay serves.

Thanks,
Alex




>Error: 500
>
>Internal Servlet Error:
>
>java.lang.IllegalStateException: cannot find message associated with key
>: serverResponse.writer.ise
>         at org.apache.tomcat.core.Response.getWriter(Response.java:217)
>         at
>org.apache.tomcat.core.HttpServletResponseFacade.getWriter(HttpServletRespo 
>nseFacade.java:150)
>
>         at
>org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:154)
>         at
>org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:146)
>
>         at
>org.apache.jasper.runtime.JspWriterImpl.flush(JspWriterImpl.java:191)
>         at
>bankingdemo._0005cbankingdemo_0005cbankIndex_0002ejspbankIndex_jsp_0._jspSe 
>rvice(_0005cbankingdemo_0005cbankIndex_0002ejspbankIndex_jsp_0.java:168)
>
>         at
>org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:126)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
>         at
>org.apache.jasper.runtime.JspServlet$JspServletWrapper.service(JspServlet.j 
>ava:161)
>
>         at
>org.apache.jasper.runtime.JspServlet.serviceJspFile(JspServlet.java:247)
>
>         at org.apache.jasper.runtime.JspServlet.service(JspServlet.java,
>Compiled Code)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
>         at
>org.apache.tomcat.core.ServiceInvocationHandler.method(ServletWrapper.java: 
>626)
>
>         at
>org.apache.tomcat.core.ServletWrapper.handleInvocation(ServletWrapper.java,
>Compiled Code)
>         at
>org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:378)
>
>         at
>org.apache.tomcat.core.Context.handleRequest(Context.java:644)
>         at
>org.apache.tomcat.core.ContextManager.service(ContextManager.java:440)
>         at
>org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(Http 
>ConnectionHandler.java:144)
>
>         at
>org.apache.tomcat.service.TcpConnectionThread.run(TcpEndpoint.java:304)
>         at java.lang.Thread.run(Thread.java:479)
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message