The Artima Developer Community
Sponsored Link

Java Answers Forum
Exception problem about OutputStream already obtained

1 reply on 1 page. Most recent reply: Mar 5, 2004 10:18 AM by Charles Bell

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 1 reply on 1 page
maxwai

Posts: 1
Nickname: maxwai
Registered: Feb, 2004

Exception problem about OutputStream already obtained Posted: Feb 25, 2004 10:30 PM
Reply to this message Reply
Advertisement
Hi all,

i'm writing a code to retrieve BLOB data from Oracle in servlet and convert it to byte[]. then forward the byte[] value to JSP for display. i'm using IBM websphere for development. The code below is what i used to display the BLOB data in JSP.

byte[] blobArr = (byte[])request.getAttribute("blobArr");
String fileType = (String)request.getAttribute("fileType");

response.reset();
response.resetBuff er();
response.setContentType(fileType);

if(fileType.equals("text/plain")) {
ByteArrayInputStream bin = new ByteArrayInputStream(blobArr);
int c;
while((c = bin.read()) != -1) {

out.print((char)c);

}
}
else {

response.getOutputStream().write(blobArr);

response.flushBuffer();
}

the problem is that although it displays the data(doc, xls...) well, it throws an exception error out :

java.lang.IllegalStateException: OutputStream already obtained

i know that it occurs when calling the method getOutputStream( ). however, why does it occur? and how to prevent it? pls someone tell me. thanks a lot!!


Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: Exception problem about OutputStream already obtained Posted: Mar 5, 2004 10:18 AM
Reply to this message Reply
You run in to this with jsp pages when you try to mix the output streams associated with the page.

You line:
response.getOutputStream().write(blobArr);
is probably the one with the problem.

It is trying write data to the output stream of the jsp page which robably was declared as html on or near the first line.

So you have the control the content type of the output and then write the correct type data to its ouput stream.

if your blobArr is a char data array, the you can create a String from it and then use

out.println(new String(blobArr));

Flat View: This topic has 1 reply on 1 page
Topic: How to parse ', (, ) and other special characters Previous Topic   Next Topic Topic: ejecting CD ROM Drive thru java code.

Sponsored Links



Google
  Web Artima.com   

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