웹프로그래밍/jsp
jsp,ajax-피라미터의 한글 처리
zelkova
2011. 5. 6. 10:19
피라미터를 한글로 전송하면 글씨가 깨지게된다.
자바스크립트는 문자열을 UTF-8로 인코딩해 주는 함수인 encodeURIComponent()함수를 제공한다.
아래와 같은 방법으로 피라미터 값을 인코딩 해 줄 수 있다.
*decodeURIComponent()
피라미터 전송하기
var params="name="encodeURIComponent("홍길동");
xhr.open("GET","/hello.jsp?"+params,true);
xhr.open("GET","/hello.jsp?"+params,true);
JSP에서 읽어오기
<%
request.setCharacterEncoding("utf-8");
String name=request.getParameter("name");
%>
request.setCharacterEncoding("utf-8");
String name=request.getParameter("name");
%>
*혹시 잘 되지 않는다면
tomcat->conf->server.xml <-메모장 열기
<Connector port="58253" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="UTF-8"/>
URIEncoding="UTF-8"/>로 바꿔주기
PHP에서 읽어오기
<?php
$name=$_POST['name'];
$nmae=iconv("utf-8","euc-kr",$name);
?>
$name=$_POST['name'];
$nmae=iconv("utf-8","euc-kr",$name);
?>
반응형