본문 바로가기
[프로그래밍]/BackEnd

JAVA - 한글 인코딩 변환 체크 한방에 끝내기

by control+c 2015. 11. 5.
반응형

JAVA - 한글 인코딩 변환 체크 한방에 끝내기           

 

String word = "무궁화 꽃이 피었습니다.";

System.out.println("utf-8 -> euc-kr        : " + new String(word.getBytes("utf-8"), "euc-kr"));

System.out.println("utf-8 -> ksc5601       : " + new String(word.getBytes("utf-8"), "ksc5601"));

System.out.println("utf-8 -> x-windows-949 : " + new String(word.getBytes("utf-8"), "x-windows-949"));

System.out.println("utf-8 -> iso-8859-1    : " + new String(word.getBytes("utf-8"), "iso-8859-1"));

System.out.println("iso-8859-1 -> euc-kr        : " + new String(word.getBytes("iso-8859-1"), "euc-kr"));

System.out.println("iso-8859-1 -> ksc5601       : " + new String(word.getBytes("iso-8859-1"), "ksc5601"));

System.out.println("iso-8859-1 -> x-windows-949 : " + new String(word.getBytes("iso-8859-1"), "x-windows-949"));

System.out.println("iso-8859-1 -> utf-8         : " + new String(word.getBytes("iso-8859-1"), "utf-8"));

System.out.println("euc-kr -> utf-8         : " + new String(word.getBytes("euc-kr"), "utf-8"));

System.out.println("euc-kr -> ksc5601       : " + new String(word.getBytes("euc-kr"), "ksc5601"));

System.out.println("euc-kr -> x-windows-949 : " + new String(word.getBytes("euc-kr"), "x-windows-949"));

System.out.println("euc-kr -> iso-8859-1    : " + new String(word.getBytes("euc-kr"), "iso-8859-1"));

System.out.println("ksc5601 -> euc-kr        : " + new String(word.getBytes("ksc5601"), "euc-kr"));

System.out.println("ksc5601 -> utf-8         : " + new String(word.getBytes("ksc5601"), "utf-8"));

System.out.println("ksc5601 -> x-windows-949 : " + new String(word.getBytes("ksc5601"), "x-windows-949"));

System.out.println("ksc5601 -> iso-8859-1    : " + new String(word.getBytes("ksc5601"), "iso-8859-1"));

System.out.println("x-windows-949 -> euc-kr     : " + new String(word.getBytes("x-windows-949"), "euc-kr"));

System.out.println("x-windows-949 -> utf-8      : " + new String(word.getBytes("x-windows-949"), "utf-8"));

System.out.println("x-windows-949 -> ksc5601    : " + new String(word.getBytes("x-windows-949"), "ksc5601"));

System.out.println("x-windows-949 -> iso-8859-1 : " + new String(word.getBytes("x-windows-949"), "iso-8859-1"));

출처 : http://gongam100.tistory.com/10


1. Form 페이지에서는 encodeURI 를 하고,

2. 처리페이지에서는 java.net.URLDecode.decode 를 해서 해결


Form : encodeURI(value,"UTF-8") 

submit() -> java : java.net.URLDecoder.decode(value,"UTF-8")


Form 페이지  

<script>

$(document).ready(function() {

//검색 클릭

$("#btn_Search").click(function() {

// search_text 값을 인코딩하여 다시 넣는다.

$("#search_text").val(encodeURI($("#search_text").val(),"UTF-8"));


$("#frm_s").attr("action", "/list.jsp");

$("#frm_s").submit();

});

});

</script>


<!--  form 부분 -->

<form id="frm_s" name="frm_s" method="get">

<input type="text" id="search_text" name="search_text" value="" title="검색어 입력" />

<input type="button" id="btn_Search" name="btn_Search" value="검색" title="검색" /> 

</form> 



처리페이지(list.jsp) 

   try{

       String search_text = request.getParameter("search_text");

       search_text  =  java.net.URLDecoder.decode(search_text,"UTF-8"); 

       System.out.println( search_text );

   }catch(java.io.UnsupportedEncodingException  e){

       System.out.println("error");

   }


http://coolmsd.tistory.com/93


반응형

댓글