You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Jeff Madynski <JM...@Netcentives.com> on 2000/01/27 00:56:35 UTC

bug

 I wanted to submit a bug with tomcat:

 In my html templates, i include some jsp files. 
 As my servlet processes html and a jsp file is to be included, a call to
 RequestDispatcherInclude is made.  
 Then the jsp does its thing, and
 I continues processing my html. I normally use JRUN and this technique
works fine.
 When I use Tomcat, it blows an illegal state exception.

 I propose the following code changes in 
jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java
 
 I have tested this and found it to be acceptable:
 
 1. getOutputStream -- either catch or throw IOException and call
 flushBuffer() if os is used, then continue processing.
 
 2. getWriter -- same thing basically (already throws IOException)
 
     public ServletOutputStream getOutputStream() throws IOException {
  started = true;
 
  if (usingWriter) {
         flushBuffer();
 // jmm test
 //      String msg = sm.getString("serverResponse.outputStream.ise");
 
 //     throw new IllegalStateException(msg);
  }
 
  usingStream = true;
 
  return out;
     }
 
     public PrintWriter getWriter() throws IOException {
  started = true;
 
  if (usingStream) {
         flushBuffer();
 // jmm test
 //     String msg = sm.getString("serverResponse.writer.ise");
 
 //     throw new IllegalStateException(msg);
  }


Re: bug

Posted by "Craig R. McClanahan" <cm...@mytownnet.com>.
Jeff Madynski wrote:

>  I wanted to submit a bug with tomcat:
>
>  In my html templates, i include some jsp files.
>  As my servlet processes html and a jsp file is to be included, a call to
>  RequestDispatcherInclude is made.
>  Then the jsp does its thing, and
>  I continues processing my html. I normally use JRUN and this technique
> works fine.
>  When I use Tomcat, it blows an illegal state exception.

>
>  I propose the following code changes in
> jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java
>

If I understand your proposal correctly, you are suggesting a change that
would make Tomcat violate the Servlet Specification.  Once you have used the
servlet output stream in a particular response, you are not allowed to use
the writer.  Likewise, once you have used the writer, you are not allowed to
use the servlet output stream.

A side effect in your case is that the calling page and the called JSP need
to use the same technique.

Craig McClanahan



Re: bug

Posted by Hans Bergsten <ha...@gefionsoftware.com>.
Jeff Madynski wrote:
> 
>  I wanted to submit a bug with tomcat:
> 
>  In my html templates, i include some jsp files.
>  As my servlet processes html and a jsp file is to be included, a call to
>  RequestDispatcherInclude is made.
>  Then the jsp does its thing, and
>  I continues processing my html. I normally use JRUN and this technique
> works fine.
>  When I use Tomcat, it blows an illegal state exception.
> 
>  I propose the following code changes in
> jakarta-tomcat/src/share/org/apache/tomcat/core/Response.java

I assume your servlet calls getOutputStream() so the IllegalStateException
is caused by the JSP implementation class calling getWriter(). That's how
it should work according to the Servlet 2.2 spec, and your changes seem to
go against the spec.

Unless I miss something, simply changing your servlet to use getWriter()
instead of getOutputStream() solves the problem you see.

Hans

>  I have tested this and found it to be acceptable:
> 
>  1. getOutputStream -- either catch or throw IOException and call
>  flushBuffer() if os is used, then continue processing.
> 
>  2. getWriter -- same thing basically (already throws IOException)
> 
>      public ServletOutputStream getOutputStream() throws IOException {
>   started = true;
> 
>   if (usingWriter) {
>          flushBuffer();
>  // jmm test
>  //      String msg = sm.getString("serverResponse.outputStream.ise");
> 
>  //     throw new IllegalStateException(msg);
>   }
> 
>   usingStream = true;
> 
>   return out;
>      }
> 
>      public PrintWriter getWriter() throws IOException {
>   started = true;
> 
>   if (usingStream) {
>          flushBuffer();
>  // jmm test
>  //     String msg = sm.getString("serverResponse.writer.ise");
> 
>  //     throw new IllegalStateException(msg);
>   }
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


-- 
Hans Bergsten		hans@gefionsoftware.com
Gefion Software		http://www.gefionsoftware.com