Win a copy of Spark in Action this week in the Open Source Projects forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Outputstream, IllegalStateException

 
Ranch Hand
Posts: 44
  • 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
 
Greenhorn
Posts: 4
  • 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
 
Greenhorn
Posts: 10
  • 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
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic