纠结了数日,终于搞定了乱码问题,归结是tomcat配置问题,在tomcat
server.xml中有2个参数是配置编码的,一个是URIEncoding,另一个是useBodyEncodingForURI.
apache tomcat官方网站对这两个参数的解释:
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.
useBodyEncodingForURI
This specifies if the encoding specified in contentType should be used for
URI query parameters, instead of using the URIEncoding. This setting is present
for compatibility with Tomcat 4.1.x, where the encoding specified in the
contentType, or explicitly set using Request.setCharacterEncoding method was
also used for the parameters from the URL. The default value is
false
.
如果http请求中,在contentType中指定了编码方式,那么将采用contentType的编码方式去解码url之后的查询参数,将忽略URIEncoding的配置.
所以在get请求时,如果contentType指定了编码方式,将会带来一定的问题(最大的问题就是,服务器端对查询字符串的编码方式无法统一),最后我决定让
useBodyEncodingForURI
参数保持默认(false):即所有的URL查询字符串的编码采用URIEncoding的参数(UTF-8),服务器端编码保持原来的统一方式.
此文档仅作总结,谢谢指教..
本文解决了Tomcat中出现的乱码问题,主要通过调整server.xml文件中的URIEncoding和useBodyEncodingForURI参数来统一GET请求中的查询字符串编码方式。
747

被折叠的 条评论
为什么被折叠?



