JavaScript form提交汉字乱码

<script type="text/javascript">

var test1="http://www.w3school.com.cn/My first/"

document.write(encodeURI(test1)+ "<br />")
document.write(decodeURI(test1))

</script>

输出
http://www.w3school.com.cn/My%20first/
http://www.w3school.com.cn/My first/

java后台解码

    String name=request.getParameter("name");

(1)  resultMsg = URLEncoder.encode(name, "utf-8");

      name = java.net.URLDecoder.decode(name,"UTF-8");

(2)  new String(request.getParameter("name").getBytes("ISO8859_1"),"UTF-8")

posted on 2018-07-30 16:51  cwone  阅读(257)  评论(0编辑  收藏  举报