1、在JSP每页的开头处写<%@ page contentType="text/html;charset=gb2312"%>
一定有, 而且要在文件首行(不能在include文件中)
2、读取数据库内容时出现的乱码可以转换一下
<%out.println(new String(rs.getString(1).getBytes("iso8859-1"),"GBK"));%> //rs.getString(1)指记录集
3、插入数据库数据是乱码。
用getBytes()的方法
//用于读数据库时由iso8859-1变为GBK
public String GBKConverter(String s_string){
try{
String des = new String(s_string.getBytes("iso8859-1"),"GBK");
return des;
}
catch(Exception ex){
String des="";
return des;
}
}
//用于处理页内生成的中文数据在写入数据库时的处理,由GBK变为iso8859-1
public String ISOConverter(String s_string){
try{
String des = new String(s_string.getBytes("GBK"),"iso8859-1");
return des;
}
catch(Exception ex){
String des = "";
return des
}
}