encodeURIComponent() 函数可把字符串作为 URI 组件进行编码
前台aJax 发送请求,通过使用encodeURIComponent
$.ajax({ type:"post", url:"metatabase!saveAll.action?inserted=" + encodeURIComponent(JSON.stringify(inser))+"&updated=" + encodeURIComponent(JSON.stringify(updat)), dataType:'json', asynchronous:false, cache:false, beforeSend:function(){ return $('#dbForm').form('validate'); }, success:function(data,status){
loadDbData();
}, error: function(){ alert("保存失败"); } });
后台Action接受时候用如下方式:
String inserted= new String(this.httpServletRequest.getParameter("inserted").getBytes("ISO8859-1"), "UTF-8");