public static String UnicodeToChinese(String s) {
try {
if (s == null || s.equals(""))
return "";
String newstring = null;
newstring = new String(s.getBytes("ISO8859_1"), "gb2312");
return newstring;
} catch (UnsupportedEncodingException e) {
return s;
}
}
public static String ChineseToUnicode(String s) {
try {
if (s == null || s.equals(""))
return "";
String newstring = null;
newstring = new String(s.getBytes("gb2312"), "ISO8859_1");
return newstring;
} catch (UnsupportedEncodingException e) {
return s;
}
}
写进数据库时用ChineseToUnicode()方法进行编码,读出来的时候用UnicodeToChinese()方法进行解码既可
posted on 2006-08-11 17:01
fly 阅读(323)
评论(0) 编辑 收藏 所属分类:
jsp学习