tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Konstantin Preißer <>
Subject RE: Tomcat strips CRLFs from the generated page
Date Mon, 13 Jan 2014 19:55:46 GMT

> -----Original Message-----
> From: Asok Chattopadhyay []
> Sent: Monday, January 13, 2014 6:41 PM
> To: Tomcat Users List
> Subject: Re: Tomcat strips CRLFs from the generated page
> Hi,
> Sorry about that.
> Here are the locations of the two files:
> (1)
> (2)
> Thanks.

I just tried your Servlet and .html locally (in Tomcat 7.0.50 on Windows, but I think the
behavior should be the same as in TC 6), and I tried your URL,
but in none of them I could find any stripped CR LFs.

If watch the source code of that URL, then e.g. Line 373 contains </body></html>
after a line break (CR LF), so the line breaks seem to work.

Some other points (which don't have to do with line breaks):

1) As Konstantin Kolinko noted, your .html page contains a lot of syntax errors.

2) Your .html page seems to be encoded in UTF-8, but your servlet uses the default encoding
to decode the bytes to a String. One some platforms the default encoding is UTF-8, but on
some like Windows it depends on the user's locale - one should explicitely set the used encoding.
(Why are you using a DataInputStream to read a .html page? A InputStream should suffice for

3) I wonder why you have this line in your servlet:

res.setHeader("X-UA-Compatible", "IE=EmulateIE7")

This instructs IE to behave like the outdated IE 7 which does not implement a lot of current
HTML functionality, but on the other hand you use a HTML5 doctype (<!DOCTYPE html>)
which seems to indicate that you intent to use the current HTML 5 features.

4) In Java 6 or earlier, it is a good practice to use try-catch-finally with resources like
PrintWriter; Java 7 has try-with-resources syntax.

Konstantin Preißer

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

View raw message