[Logo]
Forums Register Login
New lines at the beginning of the JSP output
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.
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
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...
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.
I'm curious, what problems are they causing you? Most browsers won't care about them.
bear
that's what I was wondering too
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.
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.

This thread has been viewed 4540 times.

All times above are in ranch (not your local) time.
The current ranch time is
Oct 22, 2018 08:39:48.