Struts2 后台读取get地址参数中文问题

如果是用正常的http请求则只需要转码一次,比如

string s = "中文";

s = encodeURI(s);

"http://localhost:8080/test.do?name=" + s

 

如果是用javascript请求的话,则要转码两次

 

var name = "中文";

s = encodeURI(encodeURI(s));

 

var = "http://localhost:8080/test.do?name=" + s

 

后台获取我是直接可以取到中文,网上也有人说要再解码一次,我试过有写没写都正常

try {
    this.name = java.net.URLDecoder.decode(this.name, "UTF-8");
   } catch (UnsupportedEncodingException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }

posted on 2012-07-10 10:11  低调点  阅读(179)  评论(0)    收藏  举报

导航