myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simon <skitch...@apache.org>
Subject Re: Newlines in HTTP response with text/plain
Date Mon, 18 Aug 2008 16:37:45 GMT

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.


Regards,
Simon
> 


Mime
View raw message