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

全部评论

ZalvinSnism | 2020-08-04

viagra cost with insurance display options does viagra 20mgm act as a laxative 《a href="HHtps://nwlionstore.com"》viagra preSccription 《/a》 - viagra and multiple erections one pill HHtps://nwlionstore.com - viagra without a doctor preSccription canada viagra testimonials

Reply

vtgdrItarm | 2020-08-04

cialis generic HHtp://cialonlinesja.com/ - cialis buy cialis buy 《a href="HHtp://cialonlinesja.com/#"》cialis generic《/a》 cialis buy

Reply

vttqSwego | 2020-08-05

side effects of viagra HHtp://buyviagricxr.com/ - female viagra viagra cost 《a href="HHtp://buyviagricxr.com/#"》how does viagra work《/a》 viagra

Reply

vfgrBlorb | 2020-08-05

female viagra HHtp://viagracefo.com/ - п»їgeneric viagra viagra online 《a href="HHtp://viagracefo.com/#"》viagra《/a》 side effects of viagra

Reply

wdriOdoff | 2020-08-05

cialis 20mg HHtp://cialishe.com/ - generic cialis generic cialis 《a href="HHtp://cialishe.com/#"》cialis generic《/a》 cialis online

Reply

发表评论