display binary data from DB in browser using JSP

Hello everyone:

I uploaded some files from browser and stored the files in bytes in the database, but later on I could not display the files in browser without saving them to a local storage first. Is there any way I can send the bytes to the browser in the right format using JSP?

I tried the following:

response.setContentType(..)

response.getOutputStream().write(bytes);

I can see that the browser can get the right contentType, but with a bunch of weird symbols in the browser. Please help.

Thank you very much for your time.

Heather

[601 byte] By [Heather0] at [2007-9-26 2:42:19]
# 1

I actually had to do this a few months ago. There are ways to perform this kind display using various distributed object (i.e., using MS Word OLE objects to "interpret" the byte for you, etc.). But this soon got extremely difficult to manage (and I actually had to use Perl/CGI for the majority of it).

The solution I went with was to implement a "cache" directory on the web server. Basically, the JSP/Servlet can simply check the cache and if file not there, create it from the database. Then send a redirect back to the browser to this newly-created file. The browser will then appropriately open the document. I tested this with both Netscape and IE browsers and common MIME types such as text files, MS Office docs, zip files, PDFs, RTFs.

Not ideal, but unfortunately the best I came up with.

steveEbersole at 2007-6-29 10:19:12 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...