springMVC解决get方式请求乱码问题<阿录帮帮忙>

时间:2014-12-18 13:40:51   收藏:0   阅读:202

01-【思路】

众所周知,如果是post的请求可以根据web.xml中配置org.springframework.web.filter.CharacterEncodingFilter方式来解决乱码问题,

但是get方式得请求没有被过滤器设置为想要的编码。只有通过get的请求路径去思考如何解决编码问题。

02-【解决方法01-代码解决】

String des=new String(testname.getBytes("iso-8858-1"), "utf-8");

testname:传入的get参数

des:转换编码后的值

03-【解决方法02-设置服务器请求编码方式】‘

以tomcat为例:

设置conf/server.xml-

 <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"  />

改为------->

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" URIEncoding="UTF-8" />

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!