String s = new String(Recordset1.getString("info").getBytes("ISO8859_1"),"gb2312"); 可以从request得到中文

解决方案 »

  1.   

    request.setCharacterEncoding("GBK");
    http://www.javayou.com (Java自由人)
      

  2.   

    q123a123z123(好的) ( ) 信誉:105  2004-07-14 11:42:00  得分: 0  
    这个也不行. 
     
       String s = new String(Recordset1.getString("info").getBytes("ISO8859_1"),"gb2312"); 可以从request得到中文
      
     
    错误在http://seminar.eepw.com.cn/proload/show2.jsp
      

  3.   

    服务器之间的信息传输用的是ISO8859_1而浏览器显示用的是gb2312用getParameter()的时候,是获得服务器之间传输的信息
    所以要指定编码,这就是getBytes("ISO8859_1")然后用于显示,所以要转换成gb2312
    所以String s = new String(getParameter("xxxx").getBytes("ISO8859_1"),"gb2312"); 
      

  4.   

    现在数据库中原来输入的是乱的

    http://seminar.eepw.com.cn/proload/show1.jsp
    我想把已经存到数据库中的????转化出来,我用了转换,就是
    http://seminar.eepw.com.cn/proload/show2.jsp
    可是我的转化的这一步异常呢?我的show2.jsp代码如下
    <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
    <%@ include file="Connections/access.jsp" %>
    <%
    Driver DriverRecordset1 = (Driver)Class.forName(MM_access_DRIVER).newInstance();
    Connection ConnRecordset1 = DriverManager.getConnection(MM_access_STRING,MM_access_USERNAME,MM_access_PASSWORD);
    PreparedStatement StatementRecordset1 = ConnRecordset1.prepareStatement("SELECT *  FROM embedded");
    ResultSet Recordset1 = StatementRecordset1.executeQuery();
    boolean Recordset1_isEmpty = !Recordset1.next();
    boolean Recordset1_hasData = !Recordset1_isEmpty;
    Object Recordset1_data;
    int Recordset1_numRows = 0;
    %>
    <%
    int Repeat1__numRows = 50;
    int Repeat1__index = 0;
    Recordset1_numRows += Repeat1__numRows;
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    </head><body>
    <table border="1">
      <tr>
        <td>info</td>
      </tr>
      <% while ((Recordset1_hasData)&&(Repeat1__numRows-- != 0)) { %>
      <tr>
        <td><%=(((Recordset1_data = Recordset1.getObject("info"))==null || Recordset1.wasNull())?"":Recordset1_data)%>
    <%
    // response.setContentType("text/html;charset=gb2312");
    try{
    String s = new String(Recordset1.getObject("info").getBytes("ISO8859_1"),"gb2312");
    // s = new String(Recordset1_data.getBytes("GB2312"));
    }catch(Exception e){}
    out.println(s);
    %></td>  </tr>
      <%
      Repeat1__index++;
      Recordset1_hasData = Recordset1.next();
    }
    %>
    </table>
    </body>
    </html>
    <%
    Recordset1.close();
    StatementRecordset1.close();
    ConnRecordset1.close();
    %>
      

  5.   

    如果是从文件里读出来的话可以转一下code,但如果是从数据库里读出来的话就要保证数据库的语言和本地开发语言要相同,否则会破坏传回来的数据。
      

  6.   

    request.setCharacterEncoding("gb2312");