首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

jquery表单formSerialize方法乱码有关问题解决

2012-07-02 
jquery表单formSerialize方法乱码问题解决在调用$(#downloadAttrForm).formSerialize()时,参数传至后台

jquery表单formSerialize方法乱码问题解决

在调用
$('#downloadAttrForm').formSerialize();
时,参数传至后台经常会出现乱码,无论是中文还是时间格式等,解决方法如下所示:


1、因为jquery在调用formSerialize()方法时,内部会自动encodeURIComponent方法,因此在Jsp页面中调用formSerialize()方法后,还需调用decodeURIComponent方法,示例如下所示:
var formData = $("#queryDeptBudgetForm").formSerialize();
formData = decodeURIComponent(formData, true);
?var _url="${path}/cost/queryDeptBudget.do?"+formData;

?

2、在后台处理传过来的参数时,添加以下代码:
java.net.URLDecoder.decode(params , "UTF-8");
或:

增加公用转码方法,使用该方法:

    public static String deCodeURLName(String name) {        String result = null;        try {            result = name != null ? new String(name.getBytes("ISO-8859-1"),"UTF-8") : null;        } catch (Exception e) {            e.printStackTrace();        }        return result;    }

?

热点排行