The Artima Developer Community
Sponsored Link

Java Answers Forum
clash of PrintWriter and OutputStream in servlet

2 replies on 1 page. Most recent reply: Oct 10, 2003 1:51 PM by Joe Parks

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Nandita

Posts: 10
Nickname: nanditasr
Registered: Aug, 2003

clash of PrintWriter and OutputStream in servlet Posted: Oct 9, 2003 12:06 AM
Reply to this message Reply
Advertisement
I am trying to create a pie chart in a servlet, which I am running on Domino.
Initially, on the screen, I need to show a table, followed by the pie chart below.
1. The first part is fine - I create a PrintWriter object like this:
PrintWriter pw = response.getWriter();

2. I read values from the DB, write these values into two arrays, and show the table.
3. Then I close the PrintWriter object, like this:

pw.println("</BODY></HTML>");
pw.close();
pw = null;

4. Then I put in all the code for the pie chart, and to render it on screen, I say:

OutputStream output = response.getOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(output);
encoder.encode(bi);
output.close();

5. However, I get this message at run-time:

Java.lang.IllegalStateException: can't use ServletOutputStream while PrintWriter is in use.

Can someone please tell me what I am doing wrong? I thought setting pw to null should invalidate it.
Thanks.


Rahul

Posts: 52
Nickname: wildhorse
Registered: Oct, 2002

Re: clash of PrintWriter and OutputStream in servlet Posted: Oct 9, 2003 4:20 AM
Reply to this message Reply
On any response object you can either call PrintWriter's getWriter or ServletOutputStream's getOutputStream. Not both.

Joe Parks

Posts: 107
Nickname: joeparks
Registered: Aug, 2003

Re: clash of PrintWriter and OutputStream in servlet Posted: Oct 10, 2003 1:51 PM
Reply to this message Reply
I think that you actually want two servlets, one to create the chart image, and one to create the html (including an <img> tag with the src attribute set to the URL of the image servlet).

Flat View: This topic has 2 replies on 1 page
Topic: JTable cell editing and event handling Previous Topic   Next Topic Topic: J2EE is a TWO Tier Application What DO You SAY!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use