myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tomas <>
Subject Re: Newlines in HTTP response with text/plain
Date Tue, 19 Aug 2008 00:56:43 GMT
Hello Simon,

thanks for your reply. I guess I'll parse the user agent string.


PS: My problem is not related to HTML, it's just plain text over HTTP that I'm generating.

----- Original Message ----
From: simon <>
To: MyFaces Discussion <>
Sent: Monday, August 18, 2008 1:37:45 PM
Subject: Re: Newlines in HTTP response with text/plain

On Sat, 2008-08-16 at 10:05 -0700, Tomas wrote:
> Hello,
> I don't know if this is the correct list for posting this question,
> but I have looked everywhere without finding an answer.
> I have a web application that generates a String dynamically, and the
> user can download this as a text file.
> The way to implement this is to obtain the ServletOutputStream for the
> response and writing the String directly, at the same time setting the
> "content type" for the response as "text/plain".
> The problem is that the newlines are interpreted differently under
> Windows or Linux. If I generate the String using '\n' then the file
> looks wrong when opened with Notepad. And if I generate the String
> using '\r\n' then it's wrong when opened with vi under Linux.
> I have thought about setting the correct newline using
> System.getProperty("line.separator"), but that uses the correct
> newline for the server platform, not for the client platform.
> I have also thought about parsing the user agent HTTP header, but that
> seems to me to be too much trouble and not a robust solution.
> Do you know what's the correct approach for this problem?

I don't think there is a "correct" approach here. Webapps in general are
not expected to have to handle differences in the receiving end. HTML is
HTML, regardless of what OS the browser is running on.

Feels a little odd to me that exactly the same url entered on two
different operating systems could return different results for a
downloadable file. But if you really need it, then I would think that
parsing the user agent header would be the right way to do it.

I think there are a few libraries around that parse user agent strings
(try searching on sourceforge for example). There certainly are "browser
sniffer" libraries for javascript. It probably isn't too hard to do it
yourself though.


View raw message