由于浏览器版本造成的HttpServlet获取request请求对象中含中文乱码问题
一般情况下解决页面对象的中文乱码问题,主要集中在:request、response和页面的pageEncoding设置
而我设置了以上三者后,使用post请求,没有问题,但一使用get请求方式,总是有乱码出现,纠结了将近2个小时,才怀疑是版本的问题。
通过tcp/ip monitor监视器,以及,在三个版本"火狐3.6.28国际版、Firefox15.0.1中文版和google2"1.0版来回测试,才肯定了是版本的问题,
最终原因就是我个人喜好-火狐3.6.28国际版,干净没插件,纠结这么乱码半天。
在请求地址中直接输入“http://www.etsec.com.cn:8080/web01/sayHello?name=小黑&age=20&addr=sz”,
得到的返回信息是:
http://www.etsec.com.cn:8080/web01/sayHello?name=%BA%C3%BC%D9&age=20&addr=sz
请求地址中name的值:%BA%C3%BC%D9 和JAVA的URLEncoder格式编码出来的数据 %E5%A5%BD%E5%81%87 不一致,所以没办法解析。
而使用Firefox15.0.1中文版和google2"1.0版这两个最新版本,访问都是中文显示正常,无乱码出现,且通过tcp/ip monitor监视器,他们在请示地址中的name值和JAVA的URLEncoder格式编码出来的数据 %E5%A5%BD%E5%81%87。
最后补充一点,记得查看web Project整个项目的编码格式是否utf-8,否则,乱码问题还是存在的
===========以下是监控器的内容==============
- 控制台:%E5%A5%BD%E5%81%87
- ====火狐3.6.28国际版 --版本过低=================
- GET /web01/sayHello?name=%BA%C3%BC%D9&age=20&addr=sz HTTP/1.1
- Host: localhost:8888
- User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.28) Gecko/20120306 Firefox/3.6.28
- Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
- Accept-Language: zh-cn,zh;q=0.5
- Accept-Encoding: gzip,deflate
- Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7
- Keep-Alive: 115
- Connection: keep-alive
- Cookie: JSESSIONID=AF3DFB9DB5031ED38890BB9AC638F158
- GET /web01/sayHello?name=%BA%C3%BC%D9&age=20&addr=sz HTTP/1.1
- Host: localhost:8888
- User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.28) Gecko/20120306 Firefox/3.6.28
- Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
- Accept-Language: zh-cn,zh;q=0.5
- Accept-Encoding: gzip,deflate
- Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7
- Keep-Alive: 115
- Connection: keep-alive
- Cookie: JSESSIONID=AF3DFB9DB5031ED38890BB9AC638F158
- HTTP/1.1200 OK
- Server: Apache-Coyote/1.1
- Content-Type: text/html;charset=utf-8
- Content-Length: 87
- Date: Tue, 02 Oct 201211:46:47 GMT
- <span style='color:red; font-size:30px;'>鍚嶅瓧:锟矫硷拷; 骞撮緞:20; 鍦板潃:sz</span>
- HTTP/1.1200 OK
- Server: Apache-Coyote/1.1
- Content-Type: text/html;charset=utf-8
- Content-Length: 87
- Date: Tue, 02 Oct 201211:47:00 GMT
- <span style='color:red; font-size:30px;'>鍚嶅瓧:锟矫硷拷; 骞撮緞:20; 鍦板潃:sz</span>
- 控制台:%E5%A5%BD%E5%81%87
- ====----Google chrome 21.0.1180.77============================================
- GET /web01/sayHello?name=%E5%A5%BD%E5%81%87&age=20&addr=sz HTTP/1.1
- Host: localhost:8888
- Connection: keep-alive
- Cache-Control: max-age=0
- User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.77 Safari/537.1
- Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
- Accept-Encoding: gzip,deflate,sdch
- Accept-Language: zh-CN,zh;q=0.8
- Accept-Charset: GBK,utf-8;q=0.7,*;q=0.3
- Cookie: JSESSIONID=E2D7B64BB415A8A6356F7DBF2E38B999
- HTTP/1.1 200 OK
- Server: Apache-Coyote/1.1
- Content-Type: text/html;charset=utf-8
- Content-Length: 85
- Date: Tue, 02 Oct 2012 11:48:45 GMT
- <span style='color:red; font-size:30px;'>鍚嶅瓧:濂藉亣; 骞撮緞:20; 鍦板潃:sz</span>
- 控制台:%E5%A5%BD%E5%81%87
- ======================firefix15============================================
- GET /web01/sayHello?name=%E5%B0%8F%E9%BB%91&age=20&addr=sz HTTP/1.1
- Host: localhost:8888
- User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20100101 Firefox/15.0.1
- Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
- Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
- Accept-Encoding: gzip, deflate
- Connection: keep-alive
- HTTP/1.1200 OK
- Server: Apache-Coyote/1.1
- Content-Type: text/html;charset=utf-8
- Content-Length: 85
- Date: Tue, 02 Oct 201212:15:58 GMT
- <span style='color:red; font-size:30px;'>鍚嶅瓧:灏忛粦; 骞撮緞:20; 鍦板潃:sz</span>
控制台:%E5%A5%BD%E5%81%87 ====火狐3.6.28国际版 --版本过低================= GET /web01/sayHello?name=%BA%C3%BC%D9&age=20&addr=sz HTTP/1.1 Host: localhost:8888 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.28) Gecko/20120306 Firefox/3.6.28 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: zh-cn,zh;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7 Keep-Alive: 115 Connection: keep-alive Cookie: JSESSIONID=AF3DFB9DB5031ED38890BB9AC638F158 GET /web01/sayHello?name=%BA%C3%BC%D9&age=20&addr=sz HTTP/1.1 Host: localhost:8888 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.28) Gecko/20120306 Firefox/3.6.28 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: zh-cn,zh;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7 Keep-Alive: 115 Connection: keep-alive Cookie: JSESSIONID=AF3DFB9DB5031ED38890BB9AC638F158 HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-Type: text/html;charset=utf-8 Content-Length: 87 Date: Tue, 02 Oct 2012 11:46:47 GMT <span style='color:red; font-size:30px;'>鍚嶅瓧:锟矫硷拷; 骞撮緞:20; 鍦板潃:sz</span> HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-Type: text/html;charset=utf-8 Content-Length: 87 Date: Tue, 02 Oct 2012 11:47:00 GMT <span style='color:red; font-size:30px;'>鍚嶅瓧:锟矫硷拷; 骞撮緞:20; 鍦板潃:sz</span> 控制台:%E5%A5%BD%E5%81%87 ====----Google chrome 21.0.1180.77============================================ GET /web01/sayHello?name=%E5%A5%BD%E5%81%87&age=20&addr=sz HTTP/1.1 Host: localhost:8888 Connection: keep-alive Cache-Control: max-age=0 User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.77 Safari/537.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding: gzip,deflate,sdch Accept-Language: zh-CN,zh;q=0.8 Accept-Charset: GBK,utf-8;q=0.7,*;q=0.3 Cookie: JSESSIONID=E2D7B64BB415A8A6356F7DBF2E38B999 HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-Type: text/html;charset=utf-8 Content-Length: 85 Date: Tue, 02 Oct 2012 11:48:45 GMT <span style='color:red; font-size:30px;'>鍚嶅瓧:濂藉亣; 骞撮緞:20; 鍦板潃:sz</span> 控制台:%E5%A5%BD%E5%81%87 ======================firefix15============================================ GET /web01/sayHello?name=%E5%B0%8F%E9%BB%91&age=20&addr=sz HTTP/1.1 Host: localhost:8888 User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20100101 Firefox/15.0.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3 Accept-Encoding: gzip, deflate Connection: keep-alive HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-Type: text/html;charset=utf-8 Content-Length: 85 Date: Tue, 02 Oct 2012 12:15:58 GMT <span style='color:red; font-size:30px;'>鍚嶅瓧:灏忛粦; 骞撮緞:20; 鍦板潃:sz</span>
posted on 2012-11-12 17:55 八千米海岸七厘米蔚蓝 阅读(478) 评论(0) 编辑 收藏 举报