문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
|
wiki:miscellaneous:urlencoderandurldecoder [2022/04/14 18:24] emblim98 |
wiki:miscellaneous:urlencoderandurldecoder [2023/01/13 18:44] (현재) |
||
|---|---|---|---|
| 줄 22: | 줄 22: | ||
| | 5 | **'' | | 5 | **'' | ||
| \\ | \\ | ||
| - | 컨텍스트에 따라 '' | + | 컨텍스트에 따라 '' |
| \\ | \\ | ||
| \\ | \\ | ||
| 줄 52: | 줄 52: | ||
| \\ | \\ | ||
| 이 디코더가 잘못된 문자열을 처리할 수 있는 두 가지 가능한 방법이 있습니다. 잘못된 문자를 그대로 두거나 IllegalArgumentException을 throw할 수 있습니다. 디코더가 취하는 접근 방식은 구현에 달려 있습니다.\\ | 이 디코더가 잘못된 문자열을 처리할 수 있는 두 가지 가능한 방법이 있습니다. 잘못된 문자를 그대로 두거나 IllegalArgumentException을 throw할 수 있습니다. 디코더가 취하는 접근 방식은 구현에 달려 있습니다.\\ | ||
| + | \\ | ||
| + | ==== Example 1 ==== | ||
| + | <code java> | ||
| + | package com.ocean.escapehtml; | ||
| + | import java.io.UnsupportedEncodingException; | ||
| + | import java.net.URLDecoder; | ||
| + | import java.net.URLEncoder; | ||
| + | public class PercentEncode { | ||
| + | | ||
| + | // 돌체 비타 %EB%8F%8C%EC%B2%B4+%EB%B9%84%ED%83%80 | ||
| + | | ||
| + | public static void main(String[] args) throws UnsupportedEncodingException { | ||
| + | | ||
| + | String encodedText = " | ||
| + | encodedText = URLEncoder.encode(encodedText, | ||
| + | System.out.println(" | ||
| + | // encodedText :: %EB%8F%8C%EC%B2%B4%20%EB%B9%84%ED%83%80 | ||
| + | String decodedText = encodedText; | ||
| + | decodedText = URLDecoder.decode(decodedText, | ||
| + | System.out.println(" | ||
| + | // decodedText :: 돌체 비타 | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | \\ | ||
| + | \\ | ||
| + | ==== Example 2 ==== | ||
| + | <code java> | ||
| + | package com.ocean.escapehtml; | ||
| + | import java.io.UnsupportedEncodingException; | ||
| + | import java.net.MalformedURLException; | ||
| + | import java.net.URL; | ||
| + | import java.net.URLEncoder; | ||
| + | |||
| + | public class URLEncoderExample { | ||
| + | | ||
| + | public static void main(String[] args) throws MalformedURLException, | ||
| + | // base URL | ||
| + | String baseurl = " | ||
| + | |||
| + | // String to be encoded | ||
| + | String query = " | ||
| + | |||
| + | URL url = new URL(baseurl + query); | ||
| + | System.out.println(" | ||
| + | // URL without encoding : https:// | ||
| + | |||
| + | // encode() method | ||
| + | url = new URL(baseurl + URLEncoder.encode(query, | ||
| + | System.out.println(" | ||
| + | // URL after encoding : https:// | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | \\ | ||
| + | \\ | ||
| + | ==== Example 3 ==== | ||
| + | <code java> | ||
| + | package com.ocean.escapehtml; | ||
| + | |||
| + | import java.io.UnsupportedEncodingException; | ||
| + | import java.net.MalformedURLException; | ||
| + | import java.net.URL; | ||
| + | import java.net.URLDecoder; | ||
| + | import java.net.URLEncoder; | ||
| + | |||
| + | public class URLDecoderExample { | ||
| + | | ||
| + | public static void main(String[] args) throws MalformedURLException, | ||
| + | // base URL | ||
| + | String baseurl = " | ||
| + | | ||
| + | // String to be encoded | ||
| + | String query = " | ||
| + | |||
| + | URL url = new URL(baseurl + query); | ||
| + | System.out.println(" | ||
| + | // (1) Original URL: https:// | ||
| + | |||
| + | String encodedStr = URLEncoder.encode(query, | ||
| + | url = new URL(baseurl + encodedStr); | ||
| + | System.out.println(" | ||
| + | // (2) Encoded URL : https:// | ||
| + | |||
| + | // decode() method | ||
| + | String decodedStr = URLDecoder.decode(encodedStr, | ||
| + | System.out.println(" | ||
| + | // (3) Decoded URL : https:// | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| 줄 71: | 줄 162: | ||
| \\ | \\ | ||
| [[https:// | [[https:// | ||
| + | \\ | ||
| + | [[https:// | ||
| \\ | \\ | ||
| {{tag> 오션, URLEncoder, encode, URLDecoder, decode, PercentEncoding}} | {{tag> 오션, URLEncoder, encode, URLDecoder, decode, PercentEncoding}} | ||