Error decoding url
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-06-23 09:13:56
0
2
778

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

. . . .

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(2)
淡淡烟草味

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:

<%@ page import="java.net.URLEncoder" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    System.out.println("name=" + request.getParameter("name"));
%>
<a href="?name=<%=URLEncoder.encode("你好", "UTF-8")%>">你好</a>
<a href="?name=你好">你好</a>

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!