一、在前期设计时,发现数据库中的中文是正确的,传输到页面显示时有乱码问题,用UnicodeToGb2312方法进行处理后,页面显示正确,
例:CustId = customerChange.UnicodeToGb2312(custId);
方法的写法如下:
public static String UnicodeToGb2312(String strValue) throws UnsupportedEncodingException {
if(strValue != null)
return new String(strValue.trim().getBytes("ISO-8859-1"), "gb2312");
else
return "";
}
注意事项:将页面数据保存到数据库中时,不得进行码转换,
直接赋值:CustId = custId; Javabean中采用如下写法
public void setCustId(String custId){
if(!isShow){
try{
CustId = customerChange.UnicodeToGb2312(custId);
}catch(UnsupportedEncodingException ex){
System.out.println("UnicodeToGb2312代码转换异常" ex);
}
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!



