Christian Holm wrote:

> Hi all
>
> I have been searching the net, discussion groups, usenet and more for an
> answer to the following:
>
> I'm building a JSP application, where you can attach documents to cases.
> I've written a bean which uploads the file to the underlying Oracle
> database. This is done through jdbc and a form post. I filter out the
> boundary, filename, content-type, etc, and insert the data, filename and
> content-type into the database using the setBinaryStream-method. This workes
> quite well.
> But now I want the users to be able to download these files again. Whenever
> I try to write the data to the outputstream, after having set the proper
> content-type, length, etc. the browser thinks I'm sending the entire
> jsp-file, with the filedata included. I've tried stripping the jsp-file, so
> that only the data should be in it, but still it adds a few empty lines
> before and after the data.
> I've gone around the problem by saving the file to the webserver, and then
> redirecting the browser to the file-location using javascript. This works
> fine, and looks a lot like when you download from download.com and others.
> I'm looking for a way however to stream the data directly to the browser.
> Can this be done, and how? Can you get a new outputstream just for the file,
> or what could be done?
>

I would suggest using a servlet for this purpose, rather than a JSP page.  Create a
"downloader" servlet that figures out what data to send based on the request URI,
then have it set up the content type, content length, and send the data.  Then, in
your JSP page, create a hyperlink for each file the user can download that links to
this servlet.

An advantage of this approach, over using a JSP page, is that it works fine with
binary files too, not just text.

>
> Thank you,
>
> Christian Holm
>

Craig McClanahan

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to