关于日语乱码

Windows下正常的应用移行到Solaris下后,response返回到终端的内容出现乱码。猜测原因是在没有指定编码时,输出response是用系统默认的编码。

因为用的是SpringMVC,所以开始在web.xml中加入了characterEncodingFilter,但是并没起作用,查阅后,这个只对request进行强制编码转换。后来把Solaris的编码从ja(EUC-JP)改到了UTF-8,还是不行。

最后解决办法是:

        PrintWriter out = null;
        try {
            out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), "UTF-8"));
            out.write(resJsonData);
            //            response.getOutputStream().write(resJsonData.getBytes());
        } catch (IOException e) {

        } finally {
            if (out != null) {
                out.close();
            }
        }

  

原文地址:https://www.cnblogs.com/kouen/p/3313835.html