java springmvc getHeader乱码问题解决办法

来源:深圳沃龙软件开发公司     2017-05-31

今天客户端通过header方法,传过来一个中文时,出现了乱码,折腾了半天,总算是解决了

解决办法如下:

客户端请求时:

  String ss= URLEncoder.encode("中文参数", "UTF-8");

        httpRequst.setHeader("X-Site",ss);    


springMVC服务器解析:

String str=request.getHeader("X-Site");

str = URLDecoder.decode(str);

        System.out.println(str);

      //如果上面打印出来还是乱码,那么需要再次转码,我的转码如下,请参考:

str= new String(str.getBytes("GBK"),"UTF-8");


本内容皆为 深圳沃龙软件开发公司 原创
如需转载,请注明文章出处和来源网址:http://www.wooolong.com/blog/14.html

全部评论

online_dvM | 2024-05-08

online reputation 《a href=HHtps://storesonline-reviews.com/#positive-or-negative》respond to positive reviews《/a》.

Reply

Zac | 2024-05-09

Hi there! I could have sworn I've been to your blog before but after looking at a few of the posts I realized it's new to me. Nonetheless, I'm certainly happy I came across it and I'll be bookmarking it and checking back often!

Reply

发表评论