Tomcat解决HTTP GET中文乱码

一、中文乱码原因

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。

 如:


    
    
             
          
    

 

(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。

如:


    
    
             
          
    

 

你可能感兴趣的:(Tomcat)