将从表单中接受的中文数据进行如下的重新编码,然后再将数据存入数据库中。<%!
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);
%>从数据库中读取出来的数据什么都不用做,就是正常的。

解决方案 »

  1.   

    取出来进行iso或gbk编码转换
    如果是mysql直接用    这样的url:
    jdbc:mysql://localhost/test?user=root&password=&useUnicode=true&characterEncoding=GBK
      

  2.   

    对不起啊,我早解决了,只是没空来
    我原来的代码里边有byte[] temp_t=temp_p.getBytes("ISO8859-1"); 类似的的方法,
    只是还是乱码的 我后来就这样了:  byte[] temp_t=temp_p.getBytes(); 
    就好了
    供大家参考阿
      

  3.   

    lyilei(清泉冷冰) 你的代码返回的字符串我觉得应该是UTF编码的,而不是GB2312或GBK编码!存到数据库中的数据自然也应该是UTF格式!