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();
}