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

JSP

Avatar of undefined
Last Comment
steinchen84

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
mahome

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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.
ASKER
steinchen84

Thank you for multiple solutions and explanations!
Removing the linebreaks after the directives worked for me.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck