encoding utf-8 vs euc-kr

jsp1 에서는 utf-8, jsp2 에서는 euc-kr 문자를보내주는데

utf-8에서 보내주는 한글은 깨지고
euc-kr에서 보내주는 한글은 정상적으로 받아집니다.
javascript
function fncEnCode(param)
{
// sjisbmoc
var encode = ”;
for(i=0; i<param.length; i++)
{
var len = ”+param.charCodeAt(i);
var token = ” + len.length;
encode += token + param.charCodeAt(i);
}
return encode;
}
function fncDeCode(param)
{
// sjisbmoc
var sb = ”;
var pos = 0;
var flg = true;
if(param != null)
{
if(param.length>1)
{
while(flg)
{
var sLen = param.substring(pos,++pos);
var nLen = 0;
try
{
nLen = parseInt(sLen);
}
catch(e)
{
nLen = 0;
}
var code = ”;
if((pos+nLen)>param.length)
code = param.substring(pos);
else
code = param.substring(pos,(pos+nLen));
pos += nLen;
sb += String.fromCharCode(code);
if(pos >= param.length)
flg = false;
}
}
}
return sb;
}
java
public static String EnCode(String param)
{
// sjisbmoc
StringBuffer sb = new StringBuffer();
if(param == null)
{
sb.append(“”);
}
else
{
if(param.length()>0)
{
for(int i=0; i<param.length(); i++)
{
String len = “”+((int)param.charAt(i));
sb.append(len.length());
sb.append(((int)param.charAt(i)));
}
}
}
return sb.toString();
}
public static String DeCode(String param)
{
// sjisbmoc
StringBuffer sb = new StringBuffer();
int pos = 0;
boolean flg = true;
if(param!=null)
{
if(param.length()>1)
{
while(flg)
{
String sLen = param.substring(pos,++pos);
int nLen = 0;
try
{
nLen = Integer.parseInt(sLen);
}
catch(Exception e)
{
nLen = 0;
}
String code = “”;
if((pos+nLen)>param.length())
code = param.substring(pos);
else
code = param.substring(pos,(pos+nLen));
pos += nLen;
sb.append(((char) Integer.parseInt(code)));
if(pos >= param.length())
flg = false;
}
}
}
else
{
param = “”;
}
return sb.toString();
}

Leave a Reply

Your email address will not be published. Required fields are marked *