File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Outputstream, IllegalStateException

 
Claudia Vaz
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am downloading a file from the server and saving it to the client disk.
He makes it but gives the following error:
"2001-12-13 08:44:27 - Ctx( /PS2 ): IllegalStateException in: R( /PS2 + /save.jsp
+ null) OutputStream is already being used for this request"
I don't know what's the problem since i close it.
Here is the code
"FileInputStream fileInput = new FileInputStream(pdf);
int numOfBytes = fileInput.available();
byte byteArray[] = new byte[numOfBytes];
int nextByte = fileInput.read(byteArray);
fileInput.close();
OutputStream outStream = res.getOutputStream();
outStream.write(byteArray);
outStream.close();"
Can you help me?
Thanks
Claudia
 
S.Hamid
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Claudia Vaz:
Hello,
I am downloading a file from the server and saving it to the client disk.
He makes it but gives the following error:
"2001-12-13 08:44:27 - Ctx( /PS2 ): IllegalStateException in: R( /PS2 + /save.jsp
+ null) OutputStream is already being used for this request"
I don't know what's the problem since i close it.
Here is the code
"FileInputStream fileInput = new FileInputStream(pdf);
int numOfBytes = fileInput.available();
byte byteArray[] = new byte[numOfBytes];
int nextByte = fileInput.read(byteArray);
fileInput.close();
OutputStream outStream = res.getOutputStream();
outStream.write(byteArray);
outStream.close();"
Can you help me?
Thanks
Claudia

Hi
If u write
FileOutputStream output=new FileOutputStream();instead of OutputStream outStream = res.getOutputStream();

Your problem maybe solved
 
Jerome Lumpkin
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't this really caused by trying to get another output stream long after the JSP (compiled servlet) has already allocated an output stream.
The solution would be to use the "out" object to download your data or code this as a servlet where you have control of where and how the output stream is instantiated.
Jerome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic