zoukankan      html  css  js  c++  java
  • Tomcat解决中文乱码

    一、中文乱码原因

    Tomcat默认是按ISO-8859-1进行URL解码,ISO-8859-1并未包括中文字符,中文字符不能被正确解析了。

    二、配置编码

    在tomcat的conf/server.xml下的connetor属性中增加URIEncoding或者useBodyEncodingForURI属性

    (1)URIEncoding

    This specifies the character encoding used to decode the URI bytes, after %xx decoding the URL. If not specified, ISO-8859-1 will be used.

    译文:这指定了用于解码URI字节的字符编码。如果没有指定,将使用ISO-8859-1。

     如:

    <Server port="8005" shutdown="SHUTDOWN">
        <!-- 其他配置  -->
        <Service name="Catalina">
              <Connector port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8" />   
              <!-- 其他配置  -->
        </Service>
    </Server>

    (2)useBodyEncodingForURI

    This specifies if the encoding specified in contentType should be used for URI query parameters, instead of using the URIEncoding.

    译文:这指定编码指定contentType应使用URI查询参数,而不是使用URIEncoding。

    如:

    <Server port="8005" shutdown="SHUTDOWN">
        <!-- 其他配置  -->
        <Service name="Catalina">
              <Connector port="8080" protocol="HTTP/1.1" redirectPort="8443" useBodyEncodingForURI="true" />   
              <!-- 其他配置  -->
        </Service>
    </Server>
  • 相关阅读:
    POJ
    POJ
    POJ
    POJ
    POJ
    ZOJ
    HDU
    python中主要存在的四种命名方式:
    python 中的 赋值 浅拷贝 深拷贝
    python中sorted方法和列表的sort方法使用
  • 原文地址:https://www.cnblogs.com/maokun/p/7499365.html
Copyright © 2011-2022 走看看