views:

347

answers:

2

I am generating a csv (comma separated value) file with Java Server Pages (JSP). The URL shows "my_generated_csv.jsp".

What I want to do is simple: The user clicks "Generate" which downloads the generated CSV file. I'd like to generate it with the JSP. Do I need to rethink my approach?

Edit:

The following code works to make the file downloadable, but the extension remains the same. Does anyone know how to change it?

<% response.setContentType("text/csv"); %>
+2  A: 

Have JSP save the file, and then give the user a link to the file. Either that or give the page the MIME type of a csv file (text/csv).

I believe you would use

<% response.setContentType("text/csv"); %>

To set the mime type.

It works to make the file downloadable, but the extension remains the same
fmsf
+2  A: 

Found the answer:

response.setContentType("application/csv");
response.setHeader("Content-Disposition", "inline;filename=myfile.csv");
fmsf