我的JQUERY里有这样的一句
$.get(options.source, {q: q}, function(txt) {
$results.hide();
var items = parseTxt(txt, q);
displayItems(items);
addToCache(q, items, txt.length);
});我后台String queryText = request.getParameter("q"); 如果是中文的话,此时,queryText 就乱码了另外我的TOMCAT的server.xml里有这一句useBodyEncodingForURI="true" 如果我去掉这一句,中文传值就无问题的,不会乱码但我不能去掉useBodyEncodingForURI="true" 这一句啊,求各位大虾打救下,小第在线等了

解决方案 »

  1.   


    var s = "测试";
    s = encodeURI(encodeURI(s));String s = request.getParameter("s");
    s = URIDecoder.decode(s, "UTF-8");
      

  2.   


    URIDecoder  这个是不是要先导入某个包的呢
      

  3.   

    encodeURI(encodeURI(s));不用导包的直接import就行了
      

  4.   

    问题已经解决了,谢谢一楼的方法提示啊
    JS:var newq = encodeURI(q);
    JAVA:
    try{
    queryText = URLDecoder.decode(URLDecoder.decode(queryText,"utf-8"), "gb2312");
    } catch (Exception e) {
    e.printStackTrace();
    }
      

  5.   

    那如果js不encode,java里就可以decode一次了