JS url字符串编码 java解码

ESTJS中文乱码问题的解决,

//保存添加窗口数据

总结:

简单描述:URL传输前对于参数进行编码:encodeURI(encodeURI(param.id))

          Action接收参数时对于参数进行解码:URLDecoder.decode(param.id,"UTF-8"));

例子如下:
    function onSave() {
       
if(infoForm.getForm().isValid()) {    
           
var param = infoForm.getForm().getValues(false);
             
//alert(param.roleDesc);
               infoForm.getForm().submit({
                    url:
'./json/role_add.action?role.roleid='
                       
+encodeURI(encodeURI(param.id))+'&role.roleName='
                       
+encodeURI(encodeURI(param.name))+'&role.roleDesc='
                       
+encodeURI(encodeURI(param.desc)),
                    method :
'post',                        
                    waitMsg:'正在提交角色信息...' 
                });
        }
}

//添加
public String add() throws Exception {

        role.setRoleid(URLDecoder.decode(role.getRoleid(),"UTF-8"));
        role.setRoleName(URLDecoder.decode(role.getRoleName(),
"UTF-8"));
        role.setRoleDesc(URLDecoder.decode(role.getRoleDesc(),
"UTF-8"));
        authService.addRole(role);
       
return "success";
    }

posted @ 2012-12-10 14:19  晨羲  阅读(355)  评论(0编辑  收藏  举报