你最好是自己写一个中文转换的方法,特别是在从数据库中读出中文的时候。向数据库写信息的时候好象可以不转换的。
public String getStr(String str)
{
if(str==null) {
str="";
}
String temp="";
try
{
byte[] temp_t=str.getBytes("ISO-8859-1");
temp=new String(temp_t,"Big5");
str=temp;
}
catch(Exception e)
{
System.out.println("iso8859-1 error"+e);
return null;
}
return str;
}
public String getStr(String str)
{
if(str==null) {
str="";
}
String temp="";
try
{
byte[] temp_t=str.getBytes("ISO-8859-1");
temp=new String(temp_t,"Big5");
str=temp;
}
catch(Exception e)
{
System.out.println("iso8859-1 error"+e);
return null;
}
return str;
}
加入:export LANG=zh
注意大小写哈。试试再说
你把所有的编码采用 gb2312 方式处理jsp 页面:<%@ page contentType="text/html; charset=gb2312" %>
<%request.setCharacterEncoding("gb2312");%>
byte[] temp_t=str.getBytes("ISO-8859-1");
temp=new String(temp_t);或temp=new String(temp_t,"GB2312");
sql=new String(sql.getBytes(),"8859_1");1.s=new String(s.getBytes(),"iso-8859-1");
2.s=new String(s.getBytes(),"gb2312");
3.s=new String(s.getBytes("iso-8859-1"),"gb2312");
4.s=new String(s.getBytes("gb2312"),"iso-8859-1");
5.s=new String(s.getBytes("iso-8859-1"));
6.s=new String(s.getBytes("gb2312"));
尝试以上的方法之一!
页面中添加如下代码:
<%@ page contentType="text/html;charset=gb2312" %>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
我的页面启用了<%@ page contentType='text/html; charset=GB2312' %>
这样可以使从后台来的数据以GB2312显示
还有一点当我 把后台来的数据人工转成GB2312显示出现乱码
转码代码:
private String codeString(String s){
String str=s;
String temp=""; try{
byte[] temp_t=str.getBytes("ISO-8859-1");
temp=new String(temp_t,"GB2312");
log.info("codeString = " + str);
return temp;
}
catch(Exception e)
{
log.error("e codeString = " + str);
return temp;
}
} 我怀疑orcle 数据库不是:ISO-8859-1
我怎样知道orcle 数据库的编码