Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Different behavior between getWriter and getOutputStream

 
Ted Bell
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ted Bell
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
More info: We are using WebLogic 8.1 and the content being sent is generated from a Velocity template.
 
Pavel Cherkashin
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ted Bell
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
Ted Bell
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies if I am missing something here, but any information (even an educated guess) would be appreciated.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic