你先看看从前一个JSP页面读进来的中文对不对,因为servlet默认使用iso-8859-1编码方式,所以需要对字符串首先进行重新编码,才能写数据库。

解决方案 »

  1.   

    你可以试试out.print出来,如果显示的是正确的中文,就可以直接写到数据库里去,不会乱了
    否则:String test=new String(test.getBytes("8859_1"),"gb2312");
      

  2.   

    resonse.setContentType("text/html;GB2312");
    request.setCharacterEncoding("GB2312");
      

  3.   

    肯定是没入数据库之前已经成为乱码了,所以应当在jsp或servlet时校对
      

  4.   

    1.控制面板-区域设置-英文(或直接安装英文版OS) 
    2.JSP页面中加入一条语句: 
    <%@ page contentType="text/html;charset=gb2312" %> 
    3.编译servlet使用: 
    javac -encoding iso8859-1 myservlet.java 
    在jsp的zone配置文件中,修改编译参数为: 
    compiler = builtin-javac -encoding ISO8859-1 
    4.CLASSPATH中加入i18n.jar的路径 
    5.源程序中加入代码变换函数: 
    <%! 
    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 "null"; 

    %> 
    6.如果是直接赋值的中文字串,用<%@ page contentType="text/html;charset=gb2312" %> 
    就足够了。 
    7.如果使用request传过来的中文字串,用getStr(String)方法转换后使用。 
      

  5.   

    String test=new String(test.getBytes("8859_1"),"gb2312");
      

  6.   

    写进去前用以下代码转换:
    String str=new String(str.getBytes("ISO8859_1"),"gb2312");