Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

New lines at the beginning of the JSP output

 
Bala Krishna
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Has any one faced any problem with the new line characters at the beginning of the JSP output?(Click view source on the HTML page generated by the JSP, and you will see that the actual output - the <HTML> tag starts after a few new line characters). Well, this is causing a problem for me, and I'd like to get rid of these new line characters. Did any one of you ever face this issue? Any help will be greatly appreciated. Thanks.
-Bala.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can get rid of them if they are really a problem, but it will make your JSP look awful.
The problem is that if you have something like this:

That will send two carriage return to your output.
When you start including multiple JSP tags including scriptlets, it gets worse...

You can remove the returns by wraping your tags:

Dave
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I meant to finish up by saying "the returns disappear because they are now inside the JSP tag rather than being directly output to the client" but I submitted too early...
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes -- very ugly -- those extra spaces are put in when your JSP is translated -- you might not be able to get rid of all of them depending on how the translation code is written in your appserver.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm curious, what problems are they causing you? Most browsers won't care about them.
bear
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that's what I was wondering too
 
seshu kumar
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Browsers are supposed to ignore white space. But in truth it doesnt work that way.
Specially if you have too much white space.
I had a html table being populated by jsp. Where I had significant java code.
All the white space created a empty space of about 15% of screen height above the table tag.
Only way to remove it was to rearrange the jsp as
<% ---Java Code <-cr
%><---- html code.
My jsp looks awful.
 
Bala Krishna
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all the responses. My problem is very peculiar. I have a server side Java class which 'hits' some JSPs, exchanging data via the request variable, and writes out results to a file. The JSPs do not have any HTML or out.print code. But, the new lines characters returned from the JSPs were introducing new line chars at the beginning of the file, causing some application errors.
Anyways, I've found a simpler and dirty solution to this. Add out.clear() to the code in the JSPs just before you send any output to the browser, and that removes the \ns.
Thanks again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic