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的区别吧。

相关文章:

  • 2021-07-03
  • 2021-08-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-16
  • 2021-05-15
猜你喜欢
  • 2021-08-16
  • 2021-07-23
  • 2022-02-12
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案