Link to home
Start Free TrialLog in
Avatar of steinchen84
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?
response.setContentType("application/savetodisk;charset=UTF-8");
response.setHeader("Content-Disposition","attachement; filename=list.csv");
out.flush();
out.println("ID; TITLE");
out.println("");
...

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of mahome
mahome
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mrcoffee365
Wow -- great answer, and great link to raibledesigns.

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.
Avatar of steinchen84
steinchen84

ASKER

Thank you for multiple solutions and explanations!
Removing the linebreaks after the directives worked for me.