import java.net.URLDecoder;
import java.io.UnsupportedEncodingException;
public class UrlDecodeExample {
public static void main(String[] args) {
String encodedUrl = "https://example.com/path%20with%20spaces?query=java%20url%20decode";
try {
// 使用UTF-8字符集解码URL
String decodedUrl = URLDecoder.decode(encodedUrl, "UTF-8");
System.out.println("Decoded URL: " + decodedUrl);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
%20)转换为相应的字符(如空格)。URLDecoder.decode() 时,需要指定字符集(如 "UTF-8")。这是因为不同的字符集可能会导致解码结果不同。UnsupportedEncodingException。Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站