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

3
  • What's in sImage? If it's binary data then text/html is clearly wrong. Commented Nov 11, 2010 at 3:48
  • @Jim: It's HTML in UTF-16LE encoding. (Read every second character.) Commented Nov 11, 2010 at 3: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. Commented Nov 11, 2010 at 3:53

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.