Java乱码问题解决大全

方法

    request.setCharacterEncoding(Constants.ENCODED_UTF);
    response.setContentType(Constants.CONTENTTYPE_UTF);

参考文章:

https://blog.csdn.net/tlms_/article/details/78749980

常量:

    /**
     * TODO ENCODED_编码常量,常用于编码 = ISO-8859-1
     */
    public static final String ISO88591 = "ISO-8859-1";
    /**
     * TODO ENCODED_编码常量,常用于编码 = GBK
     */
    public static final String ENCODED_GBK = "GBK";
    /**
     * TODO ENCODED_编码常量,常用于编码 = UTF-8
     */
    public static final String ENCODED_UTF = "UTF-8";

    /**
     * TODO CONTENTTYPE_编码,常用于servlet设置编码 = CONTENTTYPE_ISO88591
     */
    public static final String CONTENTTYPE_ISO88591 = "text/html;charset=" + ISO88591;
    /**
     * TODO CONTENTTYPE_编码,常用于servlet设置编码 = GBK
     */
    public static final String CONTENTTYPE_GBK = "text/html;charset=" + ENCODED_GBK;
    /**
     * TODO CONTENTTYPE_编码,常用于servlet设置编码 = UTF-8
     */
    public static final String CONTENTTYPE_UTF = "text/html;charset=" + ENCODED_UTF;

你可能感兴趣的:(乱码问题)