在你的jsp文件的开头,
<%@ page ContentType="html/text;charset=gb2312"%>这样可以的呀!
因为数据库默认的中文编码规则好象就是 gb2312,把代码贴出来,

解决方案 »

  1.   

    那你就直接用接收数据时用:
    String str = new String(str.getBytes("ISO-8859-1"),"gb2312") ;输出时在文件头上加:<%@ page ContentType="html/text;charset=gb2312"%>
      

  2.   

    \\\\\\\\\ConnMySQL.java:
    package db;
    import java.sql.*;
    public class ConnMySQL{
      Connection con=null;
      ResultSet rs=null;
      public ConnMySQL(){
        try{
          Class.forName("com.mysql.jdbc.Driver");
        }
        catch(java.lang.ClassNotFoundException e){
          System.err.println(e.getMessage());
        }
      }  public ResultSet executeQuery(String sql){
        try{
          con=DriverManager.getConnection("jdbc:mysql://155.1.1.152:3306/frkj?user=xrkj&password=xrkj&userUnicode=true&characterEncoding=GBK");
          Statement stmt=con.createStatement();
          rs=stmt.executeQuery(sql);
        }
        catch(SQLException ex){
          System.err.println(ex.getMessage());
        }
        return rs;
      }  public int executeUpdate(String sql){
        int result=0;
        try{
          con=DriverManager.getConnection("jdbc:mysql://155.1.1.152:3306/frkj?user=xrkj&password=xrkj&userUnicode=true&characterEncoding=GBK");
          Statement stmt=con.createStatement();
          result=stmt.executeUpdate(sql);
        }
        catch(SQLException ex){
          System.err.println(ex.getMessage());
        }
        return result;
      }
    }\\\\\\\\\\\\\\\\\\\\\\\\\\\Conn.jsp
    <%@ page contentType="text/html; charset=GBK" %>
    <%@ page language="java" import="java.sql.*" %>
    <jsp:useBean id="conn" scope="page" class="db.ConnMySQL"/>
    <%!
    ResultSet rs=null;
    ResultSet rsTmp=null;
    String sql="";
    int PageSize=6;
    int Page=1;
    int totalPage=1;
    String str="";public String ShowOnePage(ResultSet rs,int Page,int PageSize){
      str="";
      try{
        rs.absolute((Page-1)*PageSize+1);
      }
      catch(SQLException e){
      }
      for(int iPage=1;iPage<=PageSize;iPage++){
        str+=RsToGbook(rs);
        try{
          if(!rs.next()) break;
        }
        catch(Exception e){
          System.out.println("Locate Current Page Error!");
        }
      }
      return str;
    }public String RsToGbook(ResultSet rs){
      String tt="";
      String name="";
      String email="";
      String topic="";
      String content="";
      String reply="";
      String time="";
      try{
        name=rs.getString("guestname");
        email=rs.getString("email");
        topic=rs.getString("topic");
        content=rs.getString("content");
        reply=rs.getString("reply");
        time=rs.getString("gtime");
      }
      catch(SQLException e){
        System.out.println("Execute SQL Error!");
        System.out.println(e.toString());
      }
        tt+="<table width='600' align='center' border='1' bordercolor='#63CFCE' cellpadding='0' cellspacing='0'>";
        tt+="<tr><td width='200' height='20'>"+name+"</td><td>"+topic+"</td></tr>";
        tt+="<tr><td colspan='2' height='50'>"+content+"</td></tr>";
        tt+="<tr><td colspan='2' height='50'>"+reply+"</td></tr>";
        tt+="<tr><td colspan='2' height='20'>"+time+"</td></tr></table><br>";
        return tt;
    }
    %>
    <%
      request.setCharacterEncoding("GBK");
      sql="select * from publicbook order by gtime desc";
      try{
        rs=conn.executeQuery(sql);
      }
      catch(Exception e){
        out.println("访问数据库出错!");
      }
      rsTmp=conn.executeQuery("select count(*) as mycount from publicbook");
      rsTmp.next();
      int totalrecord=rsTmp.getInt("mycount");
      if(totalrecord%PageSize==0) totalPage=totalrecord/PageSize;
      else totalPage=(int)Math.floor(totalrecord/PageSize)+1;
      if(totalPage==0) totalPage=1;
      try{
        if(request.getParameter("Page")==null||request.getParameter("Page").equals(""))
          Page=1;
        else
          Page=Integer.parseInt(request.getParameter("Page"));
      }
      catch(java.lang.NumberFormatException e){
        Page=1;
      }
      if(Page<1) Page=1;
      if(Page>totalPage) Page=totalPage;
    %>
    <html>
    <head>
    <title>
    方瑞科技留言簿
    </title>
    </head>
    <body bgcolor="#ffffff">
    <jsp:include page="\head.html"/>
    <div align="center"><table width="800" border="0">
          <tr>
            <td height="100" bgcolor="#009999"> <div align="center">留言簿 </div></td>
          </tr>
          <tr>
            <td height="30" bgcolor="#EFEFEF"><a href="#">留言首页</a> <a href="#">我要留言</a> <a href="#">留言帮助</a> <a href="#">管理中心</a></td>
          </tr>
    </table>
    </div>
    <%
    out.println((ShowOnePage(rs,Page,PageSize)));
    %>
    <div align="center"><form action="index.jsp" method="get">
    <%
      if(Page!=1){
        out.println("<a href=index.jsp?Page=1>第一页</a>");
        out.println("<a href=index.jsp?Page="+(Page-1)+">上一页</a>");
      }
      if(Page!=totalPage){
        out.println("<a href=index.jsp?Page="+(Page+1)+">下一页</a>");
        out.println("<a href=index.jsp?Page="+totalPage+">最后一页</a>");
      }
    %>
      <p>输入页数:<input type="text" name="Page" size="3">页数:<font color="red"><%=Page%>/<%=totalPage%></font>
      </p>
    </form>
    </div>
    </body>
    </html>