1

I am trying to make a jsp page that lets user to download a .csv file. It wors fine on FF, chrome and IE10, i.e, it opens a popup to give the user the option to download/save the file. But in IE8 and safari the csv file open in the browser. How do I make it work. The code that I have is

onclick="window.location.href='../sample/SampleImport.csv'; return false;" />

Thank you in advance

user2170685
  • 13
  • 1
  • 4
  • Its probably because one browser has a plugin the other doesn't. You can't control that. You can control it for your own machine, of course, but not for your users. – developerwjk Apr 21 '14 at 19:20
  • @developerwjk If the OP wanted a particular app to open, they can't control it.. but that isn't the case. The OP specifically wants the user to download the file, not open in the browser, and this can be controlled by forcing the content to be returned as `application/octet-stream`. – Lynn Crumbling Apr 21 '14 at 19:26
  • @Lynn Crumbling, you can try it. But even there its possible a browser plugin is going off of extension rather than mimetype. – developerwjk Apr 21 '14 at 20:42

1 Answers1

0

One option would be to link off to an actual download page. That page would then push the file down as a response with a content-type of application/octet-stream

To do this, you'll probably need to write a servlet: http://balusc.blogspot.com/2007/07/fileservlet.html

As a side note, my first instinct was to response.write() out the document, but apparently that's not the correct approach.

Community
  • 1
  • 1
Lynn Crumbling
  • 12,985
  • 8
  • 57
  • 95