JavaWeb java.io.CharConversionException: Not an ISO 8859-1 character: xx

java.io.CharConversionException: Not an ISO 8859-1 character: XXX

这个问题可能是因为outputstream输出中文字造成的影响。

   
   
   
   
response.setContentType( " text/html;charset=UTF-8 " );
// response.getOutputStream().print("中文字"); // 这行会出错
response.getWriter().print( " 中文字 " ); // 换成这个就好了
response.getWriter().close();

原因我个人觉得是因为outputstream是以字节为单位输出字符串的,需要符合那个ISO 8859-1编码;但要输出的字符串是UTF8编码的,所以就有问题。但根源问题,我真没想通。

换成Writer就好了。可能是因为那个inputstream和reader,outputstream和Writer的区别吧。

转载地址:http://www.cnblogs.com/kenkofox/archive/2011/06/09/2076122.html

你可能感兴趣的:(JavaWeb java.io.CharConversionException: Not an ISO 8859-1 character: xx)