java web 页面url传值中文编码&解码问题

作者:白雪 | 创建时间: 2023-04-03
js/java 页面url传值中文编码&解码问题...
java web 页面url传值中文编码&解码问题

操作方法

创建web项目:

2:在js中添加js: function sssss(){ var act_id = ${gift.gid} ; var user_id= ${sessionScope.user.id}; var title = "${gift.gname }"; //var cont = ${url }; var itype = "3"; var tiltes = encodeURI(encodeURI(title)); var url = "<%=path %>/share/tosharegift.action?act_id=" +act_id +"&user_id=" + user_id +"&title=" + tiltes +"&itype=" + itype ; //+"&cont="+cont; $.ajax({ url:url, type:"post", dataType:'json', success:function(data){ if(data.success){ alert("分享成功!"); }else{ alert(data.errorMsg); } }, error:function(response){ alert("分享 失败!"); } });

在action中进行解码:、 String title = getWebParams().getString("title"); String cont = getWebParams().getString("cont"); if(title != null){ //编码 try { title = new String(title.getBytes("iso-8859-1"),"utf-8"); title = URLDecoder.decode(title, "utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }

温馨提示

编码要编码2c
在action层也需要2次解码
点击展开全文

更多推荐