get方式处理乱码

get方式处理乱码

 

用get方式传中文的时候,浏览器会显示%等乱码,可以

用urlEncode编码,即可以在浏览器地址栏显示中文

function checkForm(){

location.href="/esteelHome/indexSearch/1?q="+encodeURIComponent($("#q").val());

}

 

乱码处理:

发出请求jsp

parent.location.href="/web/conObj/buyDetail.do?txt_conobj_key="+objKey+"&txt_contrade_kind="+CONTRADE_KIND+"&pick_types=A&jianjibuynum=0&order_prices="+

orderPrice+"&cdListKeyArrayFront="+""+"&buyNum="+chatNum+"&ARTNFLAG="+ret.ARTNFLAG+"&CNT_KEY="+ret.CNT_KEY+"&msg="+encodeURIComponent(ret.msg);

此时传到后台是乱码(货物可购买量不足!),浏览器地址栏是正常:(货物可购买量不足!)

后台:

方法1 String MSG2 =new String(msg.getBytes("ISO-8859-1"), "UTF-8");

到了这里后变正常(货物可购买量不足!)

model.addAttribute("errorInfo", MSG2);

方法2

String MSG2 =new String(msg.getBytes("ISO-8859-1"), "UTF-8");

this.request.setCharacterEncoding("UTF-8");

this.request.setAttribute("errorInfo", MSG2);

接收请求jsp:

购买失败:${errorInfo }

 

猜你喜欢

转载自yuhuiblog6338999322098842.iteye.com/blog/2323560
今日推荐