1.test.html
运行后显示:
http://localhost:8080/test.html?name=%E4%B8%AD%E6%96%87
2.jsp进行解码
decode.jsp
<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进行URL编码,并利用Java进行解码的过程。包括了从HTML页面生成编码后的URL到Java后台进行解码的全过程。
367

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



