写道
我用的是jquery 1.3.2版本,在做ajax提交的时候中文显示乱码,后来我在网上查找了很多资料,哪怕是jquery默认的编码。。该版本用ajax提交的时候默认是utf-8的,我的jsp 后台action都是用 utf-8编码的,可是还是乱码。。
最后解决方案如下:
写道
$.ajax({
type:"POST",
url:"RoiTarget.do",
data:"roiTgId="+$(this).attr("tgid")+"&roiTgName="+encodeURI(encodeURI($(this).val())),
success:function(){
}
});
type:"POST",
url:"RoiTarget.do",
data:"roiTgId="+$(this).attr("tgid")+"&roiTgName="+encodeURI(encodeURI($(this).val())),
success:function(){
}
});
encodeURI(encodeURI($(this).val()),这个方法一定要用两遍。。为啥我也不知道,先解决问题吧
在java中获取参数。。
String roiTgName=request.getParameter("roiTgName");
URLDecoder.decode(roiTgName, "UTF-8");
URLDecoder.decode(roiTgName, "UTF-8");
先编码再解码,幸好JS中两次encodeURI之后是utf-8方式的字符。。嘿嘿