하은양 믿음군 효실맘 호홍홍집s

한글인코딩 확인하기... 본문

가벼운 배움/jsp

한글인코딩 확인하기...

호홍홍집 2014. 10. 21. 21:41

<%@ page contentType="text/html;charset=utf-8" pageEncoding="utf-8" errorPage="/errFolder/errPage.jsp" %>
<%
StringBuffer sb = new StringBuffer();
//////////////////////////////////////////////////////////////////////////////
String sPostName = request.getParameter("pname");
String sGetName = request.getParameter("gname");

String charset[] = {"utf-8","ms949","euc-kr", "ksc5601", "iso-8859-1", "8859_1", "ascii"};
for(int i = 0; i < charset.length; i++){
for(int j = 0; j < charset.length; j++){
sb.append("POST :: " + charset[i] + " --> " + charset[j] + " :::: " + ChangeEncoding(sPostName, charset[i], charset[j]) + "<br>");
}
}
for(int i = 0; i < charset.length; i++){
for(int j = 0; j < charset.length; j++){
sb.append("GET :: " + charset[i] + " --> " + charset[j] + " :::: " + ChangeEncoding(sGetName, charset[i], charset[j]) + "<br>");
}
}

//////////////////////////////////////////////////////////////////////////////
// 기본 변수 선언...
//request.setAttribute("GOTOUP_URL","index.jsp");
//dbhandle.close(dbhandle.con);
%>





<div>
POST 값: <%=sPostName%> <br>
GET 값: <%=sGetName%> <br>
<%=sb.toString()%>
</div>
<div>
<form name="frmTest" action="chkEncoding.jsp?gname=김홍집" method="post">
<input name="pname" value="김홍집"><br>
<input type="submit" value="확인">
</form>
</div>

<%!
public String ChangeEncoding(String str, String incn, String outcn) {
        if (str == null) {
            return "";
        }
        try {
            str = new String(str.getBytes(incn), outcn);
        } catch (Exception ex) {
            System.out.println("Exception:" + ex.toString());
        }
        return str;
    }
%>