javascript对url 编码(UTF-8) jsp 解码

1.test.html
<script language="JavaScript">
document.write(encodeURI('http://localhost:8080/test.html?name=中文'));
</script>


运行后显示:

        http://localhost:8080/test.html?name=%E4%B8%AD%E6%96%87

2.jsp进行解码

decode.jsp

        String url = "http://localhost:8080/test.html?name=%E4%B8%AD%E6%96%87;
        try {
            System.out.println(URLDecoder.decode(url, "UTF-8"));
            System.out.println(URLDecoder.decode(url, "GBK"));//别的编码解码后成乱码
         } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }



你可能感兴趣的:(JavaScript,html,jsp)