springmvc jsp页面href传参中文乱码问题和数据类型问题

jsp页面

例1:href="${ctx}/custbill/toselectdetail?id=${bill.shopid}&tel=${bill.customertel}&projectid=${bill.projectid}&customername="+encodeURI(encodeURI("${bill.customername}"))

例2:<a class="sub_bt_sm" id="${fundsList.num}${fundsList.num}" href="#" onClick="javascript:location.href='../funds/operating?applyId=${fundsList.applyId}&applyDirection=${fundsList.applyDirection}&businessName=' + encodeURI(encodeURI('${fundsList.businessName}')) + '&businessNumber=${fundsList.businessNumber}&applyMoney=${fundsList.applyMoney}&applyState=${fundsList.applyState}&applyUserId=${fundsList.applyUserId}&applyAccount=${fundsList.applyAccount}&applyBankName=' + encodeURI(encodeURI('${fundsList.applyBankName}')) ">申请处理</a>

//页面encodeURI编码两次,解码一次   //参数为空时为'',不是null   所以int类型的值为null时会报请求错误,可以在后台用String接收

Controller部分接收

try {       //异常
customername = URLDecoder.decode(customername, "UTF-8");
//customername = new String(customername.getBytes("ISO-8859-1"),"UTF-8");           //解码
tel = URLDecoder.decode(tel, "UTF-8");
} catch (Exception ex) {
}

-----------------------------------------------------------------------------------------------------------------------------------------------------

post中文乱码问题

var customername = $("#customername", navTab.getCurrentPanel()).val();      //取值

customername = encodeURIComponent(encodeURIComponent(customername));  //先编码再写进url

后台解码

try {
customername = URLDecoder.decode(customername, "UTF-8");
} catch (Exception ex) {
}

当能力支撑不了野心时,就该静下心来学习!
原文地址:https://www.cnblogs.com/1234cjq/p/5817472.html