본문 바로가기

개발하자/JSP&Servlet

URIEncoding-한글깨질때 설정방법

  <%
     
      request.setCharacterEncoding("euc-kr"); //method=post 한글 깨질때 쓰는방법


       //get 일때는 server.xml 에서  <Connector 부분에 URIEncoding="euc-kr"로 설정

   %>

 

ex)

 

b.jsp

============================================

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
</head>
<body>
<form action="a.jsp" method="post">
<input type="text" name="a">
<input type="submit">
</form>
</body>
</html>

 

a.jsp

=========================================================

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
</head>
<body>
<%
 request.setCharacterEncoding("euc-kr");
%>
<%=request.getParameter("a")%>
</body>
</html>