Extjs的xtype: 'searchfield'的搜索框中文乱码解决方法

来源:互联网 发布:java如何定义一个函数 编辑:程序博客网 时间:2024/04/30 04:39

extjs的grid的toolbar有个搜索框,如果输入中文搜索

后台获取是乱码

String query = req.getParameter("query");  


找到ext-4.2.1.883/examples/ux/form/SearchField.js

 onTrigger2Click : function(){
        var me = this,
            value = me.getValue();


        if (value.length > 0) {
            // Param name is ignored here since we use custom encoding in the proxy.
            // id is used by the Store to replace any previous filter
            me.store.filter({
                id: me.paramName,
                property: me.paramName,
                value: encodeURI(value)
            });
            me.hasSearch = true;
            me.triggerCell.item(0).setDisplayed(true);
            me.updateLayout();
        }
    }


将 value:value改为value:encodeURI(value)


后台获取:String query=URLDecoder.decode(req.getParameter("query"),"utf-8");即可

因为get请求url,

1:http://127.0.0.1:8080/demo2/back/product/product/read.html?_dc=1385812761051&page=1&start=0&limit=12&name=雪

请求时汉字被浏览器编码一次,

2:http://127.0.0.1:8080/demo2/back/product/product/read.html?_dc=1385812888118&page=1&start=0&limit=12&name=%E9%9B%AA

然后得自己手动编码一次( encodeURI(value)),

3:http://127.0.0.1:8080/demo2/back/product/product/read.html?_dc=1385812761051&page=1&start=0&limit=12&name=%25E9%259B%25AA

接着服务器端再解码一次,( req.getParameter("query");

4:http://127.0.0.1:8080/demo2/back/product/product/read.html?_dc=1385812888118&page=1&start=0&limit=12&name=%E9%9B%AA

然后手工再解码一次(URLDecoder.decode(req.getParameter("query"),"utf-8");)

5.http://127.0.0.1:8080/demo2/back/product/product/read.html?_dc=1385812761051&page=1&start=0&limit=12&name=雪