본문 바로가기

study/java

JAVA URL인코딩, 디코딩 – URLEncoder, URLDecoder

JAVA URL인코딩, 디코딩 – URLEncoder, URLDecoder

 aaboo  JAVA/JSP  2019년 11월 1일
URLEncoder.encode(String encodingString, String charsetName); //인코딩할 문자, 케릭터셋("UTF-8")
URLDecoder.decode(String decodingString, String charsetName); //인코딩할 문자, 케릭터셋("UTF-8")
 
 
예제
 
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
 
try{
 
   String txt = "아부탱";
   String txtEnc = URLEncoder.encode(txt, "UTF-8");
    
   System.out.println(URLEncoder.encode(txt, "UTF-8")); //%EC%95%84%EB%B6%80%ED%83%B1
   System.out.println(URLDecoder.decode(txtEnc, "UTF-8")); //아부탱
 
}catch(UnsupportedEncodingException e){
   e.printStackTrace();
}