• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP link to download a file

 
Linda Thomas
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64718
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic