wood burning stoves 2.0*
The moose likes Servlets and the fly likes JSP link to download a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "JSP link to download a file" Watch "JSP link to download a file" New topic
Author

JSP link to download a file

Linda Thomas
Ranch Hand

Joined: Jun 21, 2004
Posts: 36
I am trying to output the results of our database to a file and have the user download the file onto their computer. I have managed to get the file to be created but now on the confirmation page I want a link the user can click to download the file onto their machine where they would like to put it.

I've tried linking in Dreamweaver and it opens as an html page even tho the extension is .csv. I've tried right clicking and Save as but that also wants to save an html file.

Any suggestions how this can be done?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60781
    
  65

If you want complete control over the file disposition you should write a servlet that will stream the file to the response after setting the appropriate content headers.

As such this has been moved to the Servlets forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you would like an example of this, I have one on my site.
Go to http://simple.souther.us and download SimpleStream.
It streams images found under the WEB-INF directory but the principals are the same and it shows how to set both the contentType and contentDisposition tags to get the effect you want.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP link to download a file
 
Similar Threads
File Download and page navigation
sace target as
open file-download window from servlet
Counting Number of downloads of Static file
creating a text file from JSP