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
ASKER CERTIFIED SOLUTION
Avatar of mahome
mahome
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of mrcoffee365
mrcoffee365
Flag of United States of America image

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.
JSP
JSP

JavaServer Pages (JSP) allow the development of dynamically generated web pages. It uses the Java programming language; JSP pages are translated into servlets at runtime, with each servlet being cached and reused until the JSP is modified. JSP allows Java code to be interleaved with static web markup content, so the resulting page can be compiled and executed on the server to deliver the content.

16K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo