Problem: The Chinese decoded by Android to the background server is garbled. .
environment:
1. tomcat,在server.xml中已经明确了“utf-8".
2. 安卓已经明确了使用Utf-8编码
3. 在后台使用` java.net.URLDecoder.decode(url, "utf-8");`对url进行解码,但是解码出错。。中文是”??“。
It should be an encoding problem, but. . .
Many thanks. . .
In addition, I use the following statement to test the encoding:
if (url.equals(new String(url.getBytes("iso8859-1"), "iso8859-1"))) {
url = new String(url.getBytes("iso8859-1"), "utf-8");
System.out.println("ios8859-1");
}
if (url.equals(new String(url.getBytes("GB2312"), "GB2312"))) {
url = new String(url.getBytes("GB2312"), "utf-8");
System.out.println("gb2312");
}
Output
ios8859-1
gb2312
. . . .
Has the encoding filter been added to the background?
URLEncode/Decode is for the parameter values in the URL to avoid conflicts with the URL format itself. Tomcat will automatically decode URL parameter values, so you just need to get them directly. For example, this JSP:
In fact, there is no difference between the two "Hello" links. You can open the source code of the web page to see their link addresses. One is encoded and the other is not. But after clicking, the console will output the correct value, which means
request.getParameter("name")
The content obtained is exactly the same.