?Java?,URL?????????????????????????????????,??????????Java??URL??:
- ??
java.net.URLEncoder
?:??Java???????URL????????????encode()
?????????????:
String url = "https://example.com/search?q=Java ??"; String encodedUrl = URLEncoder.encode(url, "UTF-8"); System.out.println(encodedUrl);
-
??
%
?????????:?URL???,?????%
????????????????,????(ASCII??32)???? -
??????:?????URL???????,???(?)???(#)????(%)????URL???,????????????
URLEncoder.encode()
?????????????? -
??
java.nio.charset.StandardCharsets
?:?Java 7??,????StandardCharsets
??????????,???????UTF-8??:
String url = "https://example.com/search?q=Java ??"; String encodedUrl = URLEncoder.encode(url, StandardCharsets.UTF_8.toString()); System.out.println(encodedUrl);
- ??URL:??????????URL????,????
java.net.URLDecoder
??decode()
?????:
String encodedUrl = "https://example.com/search?q=Java+编程"; String decodedUrl = URLDecoder.decode(encodedUrl, StandardCharsets.UTF_8.toString()); System.out.println(decodedUrl);
-
?????:???URL???,???????????????????????????????,????UTF-8???,????????????
-
???URL????????:URL????????URL????????????????????,???????????????URL??????????????????
-
??????:???????????????????URL???????,Apache Commons Lang???
URLEncoderUtils
????????????????URL???