Forums Register Login

Different behavior between getWriter and getOutputStream

+Pie Number of slices to send: Send
Hi all,

I have read the documentation and different postings which state that when sending character data, using the PrintWriter from response.getWriter() is appropriate, and when sending binary data, using the OutputStream from response.getOutputStream should be used. I actually have character data to be sent in the form of a CSV file, and there is a difference in how well Excel handles the file, based on which of the above methods is used. This:




Causes Excel to fail to recognize special characters like the Euro symbol. While this:




Works just fine. I'm all for using the OutputStream, but I would like to know exactly what the nature of the difference is. Is using getWriter causing the container to do some sort of encoding on the content?

Thanks for any information.
+Pie Number of slices to send: Send
More info: We are using WebLogic 8.1 and the content being sent is generated from a Velocity template.
+Pie Number of slices to send: Send
Here is the passage from the API Documentation

public java.io.PrintWriter getWriter() throws java.io.IOException
Returns a PrintWriter object that can send character text to the client. The PrintWriter uses the character encoding returned by getCharacterEncoding(). If the response's character encoding has not been specified as described in getCharacterEncoding (i.e., the method just returns the default value ISO-8859-1), getWriter updates it to ISO-8859-1.


Is that clear?
+Pie Number of slices to send: Send
That would make sense if I were not setting the character encoding, but I am:

response.setContentType("application/ms-excel;charset=UTF-8");



In fact a line immediately after this with a call to resposne.getCharacterEncoding() returns "UTF-8".
+Pie Number of slices to send: Send
Apologies if I am missing something here, but any information (even an educated guess) would be appreciated.
The problems of the world fade way as you eat a piece of pie. This tiny ad has never known problems:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 6400 times.
Similar Threads
application/vnd.ms-excel is not working for content type?
Jsp to Excel
from where to download org.apache.poi.hssf.usermodel package???????
Printing contents
UNIX line break problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 04:09:55.