String chn_string2=new String(platenumber.getBytes("ISO-8859-1"),"GB2312")
                                                    ~~~~~~~~~~~~

解决方案 »

  1.   

    String chn_string2=new String(platenumber.getBytes("8859_1"),"GB2312")
      

  2.   

    --本地向数据库写如时的专编码转换函数
    <%!String native2Unicode(String s) 
    {
                if (s == null || s.length() == 0)
         {
                   return null;
                 }
                byte[] buffer = new byte[s.length()];
                for (int i = 0; i < s.length(); i++) 
    {
                   buffer[i] = (byte)s.charAt(i);
                }
                return new String(buffer);
            }       
    %>
    --从数据库读取显示在本地的编码转换函数
    <%!String unicode2Native(String s) 
    {
               if (s == null || s.length() == 0) {
                  return null;
               }
               char[] buffer = new char[s.length() * 2];
               char c;
               int j = 0;
               for (int i = 0; i < s.length(); i++) {
                  if (s.charAt(i) >= 0x100) {
                     c = s.charAt(i);
                     byte []buf = (""+c).getBytes();
                     buffer[j++]  = (char)buf[0];
                     buffer[j++]  = (char)buf[1];
                  }
                  else {
                     buffer[j++] = s.charAt(i);
                  }
       }
               return new String(buffer, 0, j);
    }
    %>此外你所有的方法中的"ISO8859-1"是错误的,应该是"ISO-8859-1"
      

  3.   

    <%@ page contentType="text/html;charset=gb2312" language="java" import="java.sql.*,java.io.*"%>
    <html>
    <body>
    以下是从MS SQL SERVER 数据库读取的数据:<hr>
    <table border=1>
    <tr>
    <td>图书ID号</td>
    <td>书    名</td>
    <td>出 版 社</td>
    <td>价    格</td>
    </tr>
    <%!
    String parseChinese(String in)
     {
        String s = null;
        byte temp [];
        if (in == null)
        {
            System.out.println("Warn:Chinese null founded!");
            return new String("");
        }
        try
        { 
    temp=in.getBytes("iso-8859-1");
            s = new String(temp); 
        }
        catch(UnsupportedEncodingException e)
        {
            System.out.println (e.toString());
        }
        return s;
      }
    %>
    <%! String trans(String chi)
    {
    String result=null;
    byte temp[];
    try
    {
    temp=chi.getBytes("iso-8859-1");
    result=new String(temp);
    }
    catch(UnsupportedEncodingException e)
    {
    System.out.println(e.toString());
    }
    return result;
    }
    %>
    <%!String native2Unicode(String s) 
    {
                if (s == null || s.length() == 0)
         {
                   return null;
                 }
                byte[] buffer = new byte[s.length()];
                for (int i = 0; i < s.length(); i++) 
    {
                   buffer[i] = (byte)s.charAt(i);
                }
                return new String(buffer);
            }       
    %>
    <%!String unicode2Native(String s) 
    {
               if (s == null || s.length() == 0) {
                  return null;
               }
               char[] buffer = new char[s.length() * 2];
               char c;
               int j = 0;
               for (int i = 0; i < s.length(); i++) {
                  if (s.charAt(i) >= 0x100) {
                     c = s.charAt(i);
                     byte []buf = (""+c).getBytes();
                     buffer[j++]  = (char)buf[0];
                     buffer[j++]  = (char)buf[1];
                  }
                  else {
                     buffer[j++] = s.charAt(i);
                  }
       }
               return new String(buffer, 0, j);
    }
    %><%
    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
    String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=jspdev";
    //jspdev为你的数据库名称
    String user="jiayu";
    String password="jiayu";
    Connection conn= DriverManager.getConnection(url,user,password);//Connection con=java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=jspdev","LocalSystem","LocalSystem");
    Statement stmt=conn.createStatement();
    ResultSet rst=stmt.executeQuery("select * from book order by price");
    while(rst.next())
    {
    out.println("<tr>");
        out.println("<td>"+native2Unicode(rst.getString("bookid"))+"</td>");
    out.println("<td>"+rst.getString("bookName")+"</td>");
    out.println("<td>"+rst.getString("publisher")+"</td>");
    out.println("<td>"+rst.getFloat("price")+"</td>");
    out.println("</tr>");
    }
    //关闭连接,释放资源
    rst.close();
    stmt.close();
    conn.close();
    %>
    </table>
    </body>
    </html>这是我很久以前的一个例子,看看能否对你有帮助
      

  4.   

    要不你在你的Tomcat 5.0/conf中的web.xml文件中添加如下信息:
        <mime-mapping>
            <extension>vnd.wap.wml</extension>
            <mime-type>text/vnd.wap.wml;charset=GB2312</mime-type>
        </mime-mapping>
    试试看vnd.wap.wml是你访问你的文件时的后缀名
      

  5.   

    看看这个
      一、JSP页面显示乱码二、表单提交中文时出现乱码三、数据库连 
    大家在JSP的开发过程中,经常出现中文乱码的问题,可能一至困扰着您,我现在把我在JSP开发中遇到的中文乱码的问题及解决办法写出来供大家参考。 一、JSP页面显示乱码 
    下面的显示页面(display.jsp)就出现乱码: 
    <html> 
    <head> 
    <title>JSP的中文处理</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
    </head> <body> 
    <% 
    out.print("JSP的中文处理"); 
    %> 
    </body> 
    </html> 
    对不同的WEB服务器和不同的JDK版本,处理结果就不一样。原因:服务器使用的编码方式不同和浏览器对不同的字符显示结果不同而导致的。解决办法:在JSP页面中指定编码方式(gb2312),即在页面的第一行加上:<%@ page contentType="text/html; charset=gb2312"%>,就可以消除乱码了。完整页面如下: 
    <%@ page contentType="text/html; charset=gb2312"%> 
    <html> 
    <head> 
    <title>JSP的中文处理</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
    </head> <body> 
    <% 
    out.print("JSP的中文处理"); 
    %> 
    </body> 
    </html> 二、表单提交中文时出现乱码 
    下面是一个提交页面(submit.jsp),代码如下: 
    <html> 
    <head> 
    <title>JSP的中文处理</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
    </head> <body> 
    <form name="form1" method="post" action="process.jsp"> 
    <div align="center"> 
    <input type="text" name="name"> 
    <input type="submit" name="Submit" value="Submit"> 
    </div> 
    </form> 
    </body> 
    </html> 
    下面是处理页面(process.jsp)代码: 
    <%@ page contentType="text/html; charset=gb2312"%> 
    <html> 
    <head> 
    <title>JSP的中文处理</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
    </head> <body> 
    <%=request.getParameter("name")%> 
    </body> 
    </html> 
    如果submit.jsp提交英文字符能正确显示,如果提交中文时就会出现乱码。原因:浏览器默认使用UTF-8编码方式来发送请求,而UTF-8和GB2312编码方式表示字符时不一样,这样就出现了不能识别字符。解决办法:通过request.seCharacterEncoding("gb2312")对请求进行统一编码,就实现了中文的正常显示。修改后的process.jsp代码如下: 
    <%@ page contentType="text/html; charset=gb2312"%> 
    <% 
    request.seCharacterEncoding("gb2312"); 
    %> 
    <html> 
    <head> 
    <title>JSP的中文处理</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
    </head> <body> 
    <%=request.getParameter("name")%> 
    </body> 
    </html> 三、数据库连接出现乱码 
    只要涉及中文的地方全部是乱码,解决办法:在数据库的数据库URL中加上useUnicode=true&characterEncoding=GBK就OK了。 四、数据库的显示乱码 
    在mysql4.1.0中,varchar类型,text类型就会出现中文乱码,对于varchar类型把它设为binary属性就可以解决中文问题,对于text类型就要用一个编码转换类来处理,实现如下: 
    public class Convert { 
    /** 把ISO-8859-1码转换成GB2312 
    */ 
    public static String ISOtoGB(String iso){ 
    String gb; 
    try{ 
    if(iso.equals("") || iso == null){ 
    return ""; 

    else{ 
    iso = iso.trim(); 
    gb = new String(iso.getBytes("ISO-8859-1"),"GB2312"); 
    return gb; 


    catch(Exception e){ 
    System.err.print("编码转换错误:"+e.getMessage()); 
    return ""; 



    把它编译成class,就可以调用Convert类的静态方法ISOtoGB()来转换编码。 
     
      

  6.   

    cctvnet(大虫) :你好,我的数据库是SQLSERVER,用你的方法好用吗?我试了,不行,是不是哪有什么不一样,你说的是varchar类型的属性设为binary,你是说把类型转换成binary吗?我该怎么做?angelheart() :你好,你说的数据库问题是什么问题?
      

  7.   

    yujiabian(流氓兔子雨):你的转换也不好用啊!
      

  8.   

    yyqllxh2004(潇一郎):你好,连接数库时怎么设置转码?我的是SQLSERVER数据库! gumnsteel(泡泡糖和铁丝网):真是是急啊!!!,我把什么设置页面编吗啊,还是进行字符串转码啊,都试过了,就是从数据库读出的中文显示为?号,晕yujiabian(流氓兔子雨) :问题还是从数据库读出的中文显示为?号,晕,页面中其它中文正常显示,数据库是SQLSERVER2000中文版,服务器是solaris+tomcat
      

  9.   

    数据库是SQLSERVER2000中文版,系统是WIN2000,而我的程序是在另一台服务器上,系统是solaris+tomcat
      

  10.   

    我曾经有一个项目是solaris + websphere
    数据库是oracle8
    当时开发时显示正常
    但是部署上线后数据库出来的文字是乱码
    后来更改了oracle的数据库jar包解决了问题
    你可以试试看SQLSERVER2000有没有最新的jar包
      

  11.   

    str=new String(str.getBytes("ISO8859-1","GBK"))
    试试这个
      

  12.   

    url设置成:
    jdbc:microsoft:sqlserver://ip:14433;DatabaseName=db;useUnicode=true;characterEncoding=ISO8859_1
    看看
      

  13.   

    各位大侠,还是不行啊!我用了jdbc:microsoft:sqlserver://ip:14433;DatabaseName=db;useUnicode=true;characterEncoding=ISO8859_1
    然后输入出时String name=getString("name").trim(),out.pring(name);或
    String chn_name=new String(name.getBytes("GB2312"));out.print(chn_name)或
    String chn_name=new String(name.getBytes("GB2312"));out.print(chn_name)
    都不行!头部是这样设的
    <%@ page contentType="text/vnd.wap.wml;charset=gb2312"%>
    <%request.setCharacterEncoding("UTF-8");%>

    <%@ page contentType="text/vnd.wap.wml;charset=gb2312"%>
    <%request.setCharacterEncoding("GB2312");%>也都不行,晕死我了,现在我真的怀疑是系统问题了,或JDBC版本问题了,请各各位谁有solaris下的最新JDBC驱动给我一个,我就差这个没试了!谢谢各位的帮助!!!:)
      

  14.   

    试着在网页上插入数据并显示出来,插入前对字符串用getBytes("ISO-8859-1")处理
      

  15.   

    url设置成:
    jdbc:microsoft:sqlserver://ip:14433;DatabaseName=db;useUnicode=true;characterEncoding=UTF-8
    每个页面顶上加上:
    <%@ page contentType="text/vnd.wap.wml;charset=UTF-8"%>
    <%request.setCharacterEncoding("UTF-8");%>
      

  16.   

    这么说,有可能是跨平台的问题,你可以写Email什么的咨询Sun公司一下。毕竟像你这样搞跨平台开发的可能经验都不是很多
      

  17.   

    你写一个类,让他以2进制传递,用GBK显示,不管数据库支持与否都可以
      

  18.   

    使用过滤器吧,很爽的,只需在web.xml中配一下,什么中文西文统统搞定
      

  19.   

    temp_t=temp_t.getBytes("ISO8859-1"); 
    String temp=new String(temp_t);
      

  20.   

    <script language=javascript>
    alert("ding");
    </script>
      

  21.   

    谢谢各位,看来只有楼上说的二进制显示和换个JDBC驱动没试了?请问哪个有最新的JDBC驱动!!!谢谢,还有过滤器怎么使用?