1。连接数据库的语句 String url ="jdbc:mysql://localhost:3306/test/?user=root&useUnicode=true&characterEncoding=GBK"; //注意为GBK
2。写入数据库时:用来转换编码
public String ex_chinese(String str){
try
{
String temp = new String(str.getBytes("ISO8859-1"), "GBK");
return temp;
}
catch(Exception e)
{}
return "null";
}
3。每个jsp页面加上
<%@page contentType="text/html; charset=gbk" language="java" import="java.sql.*" errorPage="" %>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">