将从表单中接受的中文数据进行如下的重新编码,然后再将数据存入数据库中。<%!
public String getstr(String str){
try
{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("ISO8859-1");
String temp=new String(temp_t);
return temp;
}
catch(Exception e)
{
return "";
}
}
%>实例如下:
<%
user_name = response.getParameter("user_name");
user_name = getstr(user_name);
%>从数据库中读取出来的数据什么都不用做,就是正常的。
public String getstr(String str){
try
{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("ISO8859-1");
String temp=new String(temp_t);
return temp;
}
catch(Exception e)
{
return "";
}
}
%>实例如下:
<%
user_name = response.getParameter("user_name");
user_name = getstr(user_name);
%>从数据库中读取出来的数据什么都不用做,就是正常的。
如果是mysql直接用 这样的url:
jdbc:mysql://localhost/test?user=root&password=&useUnicode=true&characterEncoding=GBK
我原来的代码里边有byte[] temp_t=temp_p.getBytes("ISO8859-1"); 类似的的方法,
只是还是乱码的 我后来就这样了: byte[] temp_t=temp_p.getBytes();
就好了
供大家参考阿