steinchen84
asked on
JSP to CSV generates blank lines
I am generating a csv-file through a JSP, but the csv has a lot of blank lines at the beginning of the file. If opened with MS-Excel, it starts writing in line 12. I would like it to start writing in line 1 though. What do I need to modify? Have tried different things, like comment out.flush() or changing response.setHeader information.
Does anybody know what causes the blanks?
Does anybody know what causes the blanks?
response.setContentType("application/savetodisk;charset=UTF-8");
response.setHeader("Content-Disposition","attachement; filename=list.csv");
out.flush();
out.println("ID; TITLE");
out.println("");
...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for multiple solutions and explanations!
Removing the linebreaks after the directives worked for me.
Removing the linebreaks after the directives worked for me.
We can't use the Tomcat trimSpaces parameter because we have plenty of places where we want JSP values printed with a space between them (like user names, e.g.). But for people just starting a site, they could always make sure that they put the character in where they want spaces.
We decided to switch to servlets for the CSV files, just to avoid the blank lines at the top of the CSV page.