?Java?,URL????????????????URL???????????????URL????:
- ??
java.net.URLEncoder
?????:
import java.net.URLEncoder; import java.nio.charset.StandardCharsets; public class URLEncodingExample { public static void main(String[] args) { String url = "https://example.com/search?q=Java URL Encoding"; String encodedUrl = URLEncoder.encode(url, StandardCharsets.UTF_8.toString()); System.out.println("Encoded URL: " + encodedUrl); } }
- ??
java.net.URI
?????:
import java.net.URI; import java.net.URISyntaxException; public class URLEncodingExample { public static void main(String[] args) { String url = "https://example.com/search?q=Java URL Encoding"; try { URI encodedUri = new URI(url); System.out.println("Encoded URI: " + encodedUri); } catch (URISyntaxException e) { e.printStackTrace(); } } }
- ???????????:
import java.net.URLEncoder; import java.nio.charset.StandardCharsets; public class URLEncodingExample { public static void main(String[] args) { String query = "Java URL Encoding"; String encodedQuery = URLEncoder.encode(query, StandardCharsets.UTF_8.toString()); System.out.println("Encoded Query: " + encodedQuery); } }
- ??URL:
import java.net.URLDecoder; import java.nio.charset.StandardCharsets; public class URLDecodingExample { public static void main(String[] args) { String encodedUrl = "https://example.com/search?q=Java%20URL%20Encoding"; String decodedUrl = URLDecoder.decode(encodedUrl, StandardCharsets.UTF_8.toString()); System.out.println("Decoded URL: " + decodedUrl); } }
-
????:
- ???URL?,??????????(?UTF-8)?
- ???URL?,?????????????
- ??????,?
&
?=
?+
?,?URL?????????,??????? - ???URL?,????URL???????,????????????URL?