这是别人给我回的帖子:
public class encoding{
//中文转换
String result="";
public String uni2cn(String t){
try{
result = new String(t.getBytes("GBK"),"ISO8859_1");
}catch(Exception e){
result = "";
}
return result;
} public String cn2uni(String t){
try{
result = new String(t.getBytes("ISO8859_1"),"GBK");
}catch(Exception e){
result = "";
}
return result;
}
public class encoding{
//中文转换
String result="";
public String uni2cn(String t){
try{
result = new String(t.getBytes("GBK"),"ISO8859_1");
}catch(Exception e){
result = "";
}
return result;
} public String cn2uni(String t){
try{
result = new String(t.getBytes("ISO8859_1"),"GBK");
}catch(Exception e){
result = "";
}
return result;
}
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
//中文转换
String result="";
public String str(String t){
try{
result = new String(t.getBytes("GBK"),"ISO8859_1");
}catch(Exception e){
result = "";
}
return result;
} public String strrequest(String t){
try{
result = new String(t.getBytes("ISO8859_1"),"GBK");
}catch(Exception e){
result = "";
}
return result;
}
<%@ page contentType="text/html;charset=gb2312"%>
//中文转换
String result="";
public String uni2cn(String t){
try{
result = new String(t.getBytes("GBK"),"ISO8859_1");
}catch(Exception e){
result = "";
}
return result;
} public String cn2uni(String t){
try{
result = new String(t.getBytes("ISO8859_1"),"GBK");
}catch(Exception e){
result = "";
}
return result;
}
str=new String(str.getBytes("8859_1"),"gb2312");
str=new String(str.getBytes("gb2312"),"8859_1");
一前一后转换。
public String getStr(String str)
{
byte[] bytestr = str.getBytes("ISO8859-1");
str = new String(bytestr);
return str
}
%>
一般就是编码格式的问题,通常可以打成byte看一下乱码是什么编码格式,然后转成能显示的就行了。。说了这么多 , 等于没说嘻嘻 :)
我刚做完跟他配置完全一样
加入数据库时charset=gb2312
取出数据之后把数据转换一下
new String(**.getBytes("iso8859_1"),"gb2312")
完全就可以了啊
用这个也可以解决吧