我有这个网址:http://localhost:8080/Test/jsp/index.jsp?userName=%E5%AE%98%E8%AF%9D
。但是当我尝试获取 userName
时:
<meta http-equiv="test" content="text/html; charset=UTF-8">
<%
String username = request.getParameter("userName");
out.print("<b>"+username+"</b>");
%>
打印的userName
不可读。我的页面已经是UTF-8,并且保存为UTF-8,如何获取并打印准确的汉字?
最佳答案
您应该对 URL 进行编码(这是 Python,使用等效的 Java 方法):
>>> urllib.urlencode({'userName':'官话'})
'userName=%E5%AE%98%E8%AF%9D'
关于java - 无法获取URL中的中文字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10223415/