[Java] get 방식으로 한글 파라메터 전송시 한글꺠짐

2013. 9. 10. 13:36개발언어/Java

get 방식으로 한글 파라메터 전송시 한글꺠짐 현상

 - 브라우저는 캐릭터인코딩을 ISO-8859-1로 인코딩하여 URL로 보내게 된다. 그래서 UTF-8이나 EUC-KR로 디코딩   하게 되면 한글이 깨진다


http://localhost:8080/logon/test.do?test=테스트


  @RequestMapping("/test")

public ModelAndView test(HttpServletRequest request, HttpServletResponse response) {

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

try {

if(test != null){

test = new String(test.getBytes("8859_1"),"UTF-8"); // getBytes("8859_1") 

}

} catch (UnsupportedEncodingException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

    log.info(test);

return null;

}