背景一:
ajax请求后台action,在action中获取参数乱码
解决方法:
Ajax请求时加入代码
contentType: "application/x-www-form-urlencoded; charset=utf-8"
例如:
$.ajax({
type: 'POST',
url: "${ctx}/approvingMoney!approvingMoney.action",
data:{
"subjectnames":subjectnames,
"budgetSection":budgetSection,
"subjectids":subjectids,
"costyear":nr
},contentType: "application/x-www-form-urlencoded; charset=utf-8",
async: false,
success: function(data) {
var json = eval("("+data+")").data;
var approvingMoney = json.approvingMoney;
var currentCumulativeMoney = json.currentCumulativeMoney;
opener.$("input[name='whir$t3082_f3831']")[<%=rowIndex%>].value=approvingMoney;//审批中金额
opener.$("input[name='whir$t3082_f3832']")[<%=rowIndex%>].value=currentCumulativeMoney;//当前累计金额
opener.$("input[name='whir$t3082_f3833']")[<%=rowIndex%>].value=(approvingMoney+currentCumulativeMoney+baoxiaoMoney).toFixed(2);//累计预算总额
},
error: function() {
alert("出错啦");
}
});
背景二:
在jsp页面使用url访问action,带有中文的参数拼接在url中,在action中获取参数乱码
解决方法:
在jsp先转码
在后台重编码
bfyr = new String(this.request.getParameter("bfyr").getBytes("iso-8859-1"),"UTF-8");