Tomcat中ISO-8859-1转UTF-8中文乱码的问题

来源:互联网 发布:cla 知乎 编辑:程序博客网 时间:2024/05/18 02:09

这里写图片描述

一开始以为是gzip配置问题,后来在后台打日志中看到是字符转码出现问题:

/**     * 字符转换     * @param str     * @return     * @throws UnsupportedEncodingException     */    public static String characterEncode(String str) throws UnsupportedEncodingException{        String method = ParamUtil.getRequest().getMethod();        // 获取系统的编码        String systemChartCode = "UTF-8";        if ("get".equals(method.toLowerCase())){            return  new String(str.getBytes("ISO-8859-1"),systemChartCode);        }else{            return str;        }    }

本来是没问题的,tomcat默认编码是ISO-8859-1,但是!!

<Connector executor="tomcatThreadPool"               URIEncoding="utf-8"                port="5095" protocol="HTTP/1.1"               connectionTimeout="20000"               redirectPort="3443" acceptCount="200"                compression="on"                compressionMinSize="50"               noCompressionUserAgents="gozilla, traviata"               compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"/>

URIEncoding=”utf-8” 这个导致tomcat默认编码变成utf-8了,后续转码失败变成乱码。

阅读全文
0 0
原创粉丝点击