jsp中将链接http传递中文数据至action中发生乱码现象的解决

来源:互联网 发布:mac chrome 书签备份 编辑:程序博客网 时间:2024/06/05 06:53

比如需要将

var name = "中文";url:'${pageContext.request.contextPath}/send?code='+code+'&name='+name;
将数据name发送到action后,使用String a = response.getCharacterEncoding(); 可以发现a为iso-8859-1

解决方法:

<pre name="code" class="html">url:'${pageContext.request.contextPath}/send?code='+code+'&name='+encodeURI(encodeURI(name);

action中:

String name = URLDecoder.decode(request.getParameter("name"),"UTF-8");
这样就能解决乱码问题了。

0 0
原创粉丝点击