• Post Reply Bookmark Topic Watch Topic
  • New Topic

File download Problem  RSS feed

 
Arun Kumar
Ranch Hand
Posts: 135
Chrome Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my application there is an option to export data from a table as a csv file

now when the user submits a page a csv file has to be created and I am streaming the output of the csv to the browser

res.setContentType("application/vnd.ms-excel");
OutputStream ros = res.getOutputStream();
ros.write(..........);
ros.close();


what mime type should i use inorder to download the file as .csv when i use application/vnd.ms-excel it tries to save the file as excel

and how do i set the file name of the file to be downloaded now it tries to save the file in the name of the servlet
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any mime extension that the browser doesn't recognize or have an application mapping for will cause it to prompt the user to download the file.
Try text/csv.

The Content-Disposition header allows you to set the name of the file.
You can see an example of its use in this FAQ entry.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!