编码后获得的值乱码主要原因是前后字符集不一样。
大部分浏览器现在发起GET请求时编码采用encodeURIComponent,这个函数表示把页面上的内容以UTF-8编码。
所以Tomcat在配置时需要使用UTF-8
<Connector executor="tomcatThreadPool" port="xxx" protocol="HTTP/1.1" connectionTimeout="xxxx" URIEncoding="utf-8"/>
<Connector port="xxx" protocol="AJP/1.3" redirectPort="xxx" URIEncoding="utf-8"/>
当使用AJP时,因为apache2.2后发送到tomcat默认就是utf-8,所以AJP使用utf-8则不会有乱码。
直接请求tomcat(中间不经过apache),URIEncoding="utf-8“
哲涛平台专用函数:
g、vg、gt、gp获取时进行了转码。需要注意配置中有:URL编码要与tomcat的一致。(VERIP系统级配置中的系统默认网址编码)
16进制编码,直接发给tomct会报400错,需要把16进制的转义符以URL编码,比如:\u4f60变成:%5Cu4f60,这样就不会乱码了!