1

I am using HttpServletResponse wrapped with JSF 2.1 in order to make a download button. Following the instructions of this answer: https://stackoverflow.com/a/9394237/870122

Since I want to download a csv file, I use the following headers:

FacesContext fc = FacesContext.getCurrentInstance();
ExternalContext ec = fc.getExternalContext();
ec.responseReset();
String fileName = "MyFile.csv";
ec.setResponseContentType("text/plain");
ec.setResponseHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");

The download completes successfully with both IE9 and FF, but with the second I see that the browser adds a ".txt" extension that I would like to avoid.

Community
  • 1
  • 1
perissf
  • 15,979
  • 14
  • 80
  • 117

1 Answers1

2

Perhaps you should try by setting the response content type to text/csv

zoom
  • 1,686
  • 2
  • 16
  • 27
  • Thanks, your solution works perfectly, although I couldn't find an authoritative reference to this content type around... – perissf Jan 12 '13 at 22:22
  • Try looking at [wikipedia](http://en.wikipedia.org/wiki/Comma-separated_values) and more specifically [RFC 4180](http://tools.ietf.org/html/rfc4180) – zoom Jan 12 '13 at 22:31