处理js传参数有中文乱码的情况
js编码 :
var comment = document.all.comment.value;
comment = encodeURI(comment );
comment = encodeURI(comment );//注重要两次
action解码
String comment = request.getParameter("comment ");
try {
comment = java.net.URLDecoder.decode(comment, "utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
本文介绍了一种解决JavaScript传递含有中文字符参数时出现乱码的方法。通过两次使用encodeURI进行编码,并在服务器端使用URLDecoder.decode进行解码,确保了中文字符能够正确传输。

被折叠的 条评论
为什么被折叠?



