You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by RS...@TRANSENTRIC.COM on 2001/12/13 23:45:44 UTC

RE: Thanks Larry - java.lang.IllegalStateException - code included.....

Larry,
Thanks. It's amazing how reading the docs closely helps!
RS





RSEQUEIRA@TRANSENTRIC.COM on 12/13/2001 03:56:16 PM

Please respond to "Tomcat Users List" <to...@jakarta.apache.org>

To:   "Tomcat Users List" <to...@jakarta.apache.org>
cc:

Subject:  RE: java.lang.IllegalStateException - code included.....


I'm a little lost here with your reply. (And apparently a little slow too.
:-)
I'm using just the getOutputStream in the calling servlet. This
outputstream is required to direct the input that the called servlet
returns, to the browser.

Thanks.
RS






Larry Isaacs <La...@sas.com> on 12/13/2001 03:31:36 PM

Please respond to "Tomcat Users List" <to...@jakarta.apache.org>

To:   'Tomcat Users List' <to...@jakarta.apache.org>
cc:

Subject:  RE: java.lang.IllegalStateException - code included.....

The Javadoc for ServletResponse states for getWriter():

    Either this method or getOutputStream() may be called
    to write the body, not both.

Since in Tomcat 3.x, the same response is passed to the
called servlet, so this restriction applies to it too.
- I'm confused here ???

Cheers,
Larry

> -----Original Message-----
> From: RSEQUEIRA@TRANSENTRIC.COM [mailto:RSEQUEIRA@TRANSENTRIC.COM]
> Sent: Thursday, December 13, 2001 4:16 PM
> To: Tomcat Users List
> Subject: Re: java.lang.IllegalStateException - code included.....
>
>
>
> Thought if I include the code it might help a little:
>
> Piece of code in the calling servlet:
>          ..............
>          ..............
>          in = new BufferedReader(new
> InputStreamReader(uconn.getInputStream
> ()));
>          resp.setContentType("text/html");
>          System.err.println("About to read and output content using
> PrintStream....");
>          String line;
>          PrintStream pw = new
> PrintStream(resp.getOutputStream(), true);
>          while((line = in.readLine()) != null)
>          {
>             pw.println(line);
>             pw.flush();
>             System.err.println("Flushed data back....");
>          }
>          pw.flush();
>          in.close();
>          ..............
>          ..............
>
> where,
> uconn is the URLConnection to the called servlet.
>
> Maybe I should buffer the output before I send it across to
> the browser.
>
> Still waiting :-)
> Thanks.
>
>
>
>
>
> (Embedded image moved to file: pic04041.pcx)
> Roshan A. Sequeira
> (Embedded image moved to file: pic03602.pcx)
> 12/13/2001 11:57 AM
>
> To:   "Tomcat Users List" <to...@jakarta.apache.org>
> cc:
>
> Subject:  java.lang.IllegalStateException
>
>
> I'm calling a servlet from within another servlet using the
> URL class. The
>       calling servlet posts data, reads the output, and then
> passes on the
>       output to the browser. In JRun everything works fine.
> But on Tomcat
>       the same throws a java.lang.IllegalStateException
>
> Error:
> java.lang.IllegalStateException: Writer is already being used for this
> request
>         at
> org.apache.tomcat.facade.HttpServletResponseFacade.getOutputSt
> ream(HttpServletResponseFacade.java:158)
>
> I'm using a PrintWriter (which I get from the response object) in the
> called servlet. And I've a finally block which closes the stream. Also
> assign the object to null.
>
> The calling servlet which behaves like a proxy has a
> PrintStream (which it
> gets from it's response object). This object is used to write
> the output
> (that it reads from the called servlet) to the browser.
>
> I know I'm missing something fundamental here. But can't seem
> to figure it
> out. Is Tomcat getting mixed up with two  Outputstreams/Writers? Any
> ideas/comments?
>
> Thanks.
> RS
>
>
>
>

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









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









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