2

i have used

StringWriter writer = new StringWriter();
request.setCharacterEncoding("ISO-8859-1");
response.setContentType("text/html;charset=ISO-8859-1");
pw =response.getWriter();
IOUtils.copy(sImage, writer);
theString = writer.toString();
pw.write(theString);
pw.flush();

In the client browser am getting output as

ÿþ<�h�t�m�l� �x�m�l�n�s�:�v�=�"�u�r�n�:�s�c�h�e�m�a�s�-�m�i�c�r�o�s�o�f�t�-�c�o�m�:�v�m�l�"� � �x�m�l�n�s�:�o�=�"�u�r�n�:�s�c�h�e�m�a�s�-�m�i�c�r�o�s�o�f�t�-�c�o�m�:�o�f�f�i�c�e�:�o�f�f�i�c�e�"� � �x�m�l�n�s�:�w�=�"�u�r�n�:�s�c�h�e�m�a�s�-�m�i�c�r�o�s�o�f�t�-�c�o�m�:�o�f�f�i�c�e�:�w�o�r�d�"� � �x�m�l�n�s�:�x�=�"�u�r�n�:�s�c�h�e�m�a�s�-�m�i�c�r�o�s�o�f�t�-�c�o�m�:�o�f�f�i�c�e�:�e�x�c�e�l�"� � �x�m�l�n�s�:�p�=�"�u�r�n�:�s�c�h�e�m�a�s�-�m�i�c�r�o�s�o�f�t�-�c�o�m�:�o�f�f�i�c�e�:�p�o�w�e�r�p�o�i�n�t�"� � �x�m�l�n�s�:�a�=�"�u�r�n�:�s�c�h�e�m�a�s�-�m�i�c�r�o�s�o�f�t�-�c�o�m�:�o�f�f�i�c�e�:�a�c�c�e�s�s�"� �

If any of you guys know this,how can i solve this problem

Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
pras
  • 21
  • 1
  • 2
  • What's in sImage? If it's binary data then text/html is clearly wrong. – Jim Garrison Nov 11 '10 at 03:48
  • @Jim: It's HTML in UTF-16LE encoding. (Read every second character.) – C. K. Young Nov 11 '10 at 03:48
  • Well then Chris Jester-Young's answer is correct. Setting the content type and character encoding headers don't actually make the output match. YOU have to do that by setting the appropriate encoding in the writer. Either set the headers to match the actual data, or convert the data to match the ISO-8859-1 header. – Jim Garrison Nov 11 '10 at 03:53

1 Answers1

1

Try using this:

response.setContentType("text/html; charset=UTF-16LE");

Granted, it doesn't make your text ISO-8859-1, but, most browsers have no problem supporting UTF-16 these days.

C. K. Young
  • 219,335
  • 46
  • 382
  • 435
  • @pras: Your browser doesn't like the byte-order mark (BOM)? Try using `UTF-16` instead of `UTF-16LE`. Though, your browser violates RFC 2781, which says that the BOM is supposed to be accepted (but optional) if `UTF-16LE` is used. – C. K. Young Nov 11 '10 at 05:44