tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier>
Subject Re: Tomcat strips CRLFs from the generated page
Date Mon, 13 Jan 2014 14:36:31 GMT
Asok Chattopadhyay wrote:
> Hi,
> My servlet generates a page containing embedded JavaScript and sometimes
> the page received in the browser comes with CRLFs stripped from the text,
> starting at some point in the text. This creates a big problem if the
> script contains CRLF as statement separator instead of semi-colon. It's
> strange that not the entire text is stripped. Say, the first 150 lines
> comes as it is, whereas starting from line 151, all the CRLFs are stripped.
> It is fairly consistent for the same page.
> I am using Tomcat 6.0.37.
> Why does it happen? Is anything in the text triggers this? Is there a way
> to overcome this problem, as I don't have control over the actual content?
> Thanks in advance.
> Here is the example.
> LINE 148:    <script type="text/javascript"
> SRC="html/scripts/combotext.js"></script>
> LINE 149:    <script type="text/javascript"
> SRC="html/scripts/datepicker.js"></script>
> LINE 150:    <script type="text/javascript"
> SRC="html/scripts/combo.js"></script>
> LINE 151:    <script type="text/javascript"
> SRC="html/scripts/calc.js"></script>    <script type="text/javascript"
> SRC="html/scripts/dream.js"></script><script language="javascript"
> type="text/javascript">var buttonfunction
> clicked(b){button=b.value}function submitit(form){if
> (button=="Details"){ = "opcdt"form.searchbutton.value =
> "Top"}}function pickProduct(link, cus){if
> (navigator.appName.indexOf("Netscape") >=
> 0){}else{}return
> false}</script></head><body
> onload="topBottom();move_caret('one','xcrnnum');"
> style="margin:0;padding:0;"><!--<div id="darkBackgroundLayer"
> class="darkenBackground"> ...

I have to disregard your example above, because once reformated by the various email 
agents in-between, there is no telling anymore what the original was like.

In general, are you not just victim of the following circumstances ?

In HTML (and I suppose that this also includes embedded <script>..</script> sections,
"end of line" is composed of 2 characters : a "carriage return" (CR) and a "line feed" (LF).

When you are running a java program, the "println" function probably appends an "end of 
line" sequence to what you are printing, but this end of line sequence depends on the 
platform on which your java program runs :
- on a Windows system, the end of line sequence would be CR + LF
- on a Unix/Linux system, it will be just LF
- on a Mac system, it would be just CR

So depending on what platform your server is running, and on what platform the client is 
running, they may interpret the result differently.

In other words, if your java application is outputting HTML and/or javascript, you should

probably not be using "println".  You should be using "print", and explicitly append a CR

and LF to your output lines.  ("\r\n" ?).

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message