This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSP and the fly likes Writing byte data through jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Writing byte data through jsp" Watch "Writing byte data through jsp" New topic
Author

Writing byte data through jsp

Chris Reeves
Ranch Hand

Joined: Apr 03, 2002
Posts: 95
I need to return a file to the browser through a jsp. The file contains binary data, so I need to return bytes.
Here's the catch: I'm writing the jsp to run under coldfusion mx. So, while I would normally call getOutputStream, I encounter a java.lang.IllegalStateException when calling getOutputStream. This means that getWriter has already been called.
So, I'm stuck with a writer, trying to write bytes. The writer is happy to write the bytes (which return as integers), or I can convert them to char.
This output is close to the original, but doesn't product the file I'm returning exactly. I blame this on the character encoding used by the Writer.
Any suggestions on how to coerce the writer to write bytes without any encoding? Or other ideas? I'm stuck with the writer, as coldfusion seems to take care of that on its own.
Thanks!
Chris
Andy Bowes
Ranch Hand

Joined: Jan 14, 2003
Posts: 171
Hi Chris,
I think you will need to use a servlet rather than a JSP page to send a binary file back to clients browser. I don't know the ColdFusion MX architecture, is that feasible ?


Andy Bowes<br />SCJP, SCWCD<br />I like deadlines, I love the whoosing noise they make as they go flying past - Douglas Adams
Chris Reeves
Ranch Hand

Joined: Apr 03, 2002
Posts: 95
Andy, you took the words right out of my mouth.
I am going to try it with a servlet - I know that will work.
But, if anyone else has any ideas, please chime in.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Writing byte data through jsp