为什么我的jsp页面对检索出来的数据重复多次显示?如何解决这个问题?谢谢(服务器:tomcat 5.5.12)

解决方案 »

  1.   

    如下为代码:麻烦大家啦<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.io.*"  %>
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head>
    <jsp:useBean id="con" scope="page" class="common.ConnectionBean" />
    <body background="../images/BK.jpg"><center>
    <script  language="JavaScript" src="check.js"></script><%
       int intPageSize; //一页显示的记录数 
       int intRowCount; //记录总数 
       int intPageCount; //总页数 
       int intPage; //待显示页码 
       String strPage; 
       int i;    //设置一页显示的记录数 
       intPageSize = 6;   //取得待显示页码 
      strPage = request.getParameter("page"); 
      if(strPage==null){//表明在QueryString中没有page这一个参数,此时显示第一页数据 
      intPage = 1; 
      } 
      else{//将字符串转换成整型 
      intPage = Integer.parseInt(strPage); 
      if(intPage<1) intPage = 1; 
      } 
       String temp="";
       String id="";
       String Table="";
       id=con.codeString(request.getParameter("ID"));//此ID为列拉列表框中optionID值
       if(id.intern()=="1".intern())
       {
      Table="tb_zggb";
      temp="中国古币";
       }
       else if(id.intern()=="2".intern())
       {
       Table="tb_mghb";
       temp="民国货币";
       }
       else if(id.intern()=="3".intern())
       {
       Table="tb_gjdhb";
       temp="根据地货币";
       }
       else if(id.intern()=="4".intern())
       {
       Table="tb_zgpz";
       temp="中国票证";
       }
       else if(id.intern()=="5".intern())
       {
       Table="tb_zggp";
       temp="中国股票";
       }
       else if(id.intern()=="6".intern())
       {
       Table="tb_rmb";
       temp="人民币";
       }
       else if(id.intern()=="7".intern())
       {
       Table="tb_gathb";
       temp="港澳台货币";
       }
       else if(id.intern()=="8".intern())
       {
       Table="tb_dzhb";
       temp="电子货币";
       }
       else if(id.intern()=="9".intern())
       {
       Table="tb_wghb";
       temp="外国货币";
       }
       else if(id.intern()=="10".intern())
       {
       Table="tb_jnb";
       temp="纪念币";
       }
       else if(id.intern()=="11".intern())
       {
       Table="tb_gdhb";
       temp="广东货币";
       }   else if(id.intern()=="12".intern())
       {
       Table="tb_mqzb";
       temp="明清纸币";
       }
       %>
    <%   con.setCon();
       String Sql="select * from "+Table+" order by CurNO asc"; 
       ResultSet result=con.query(Sql);
       //ResultSet result=con.query(Sql);
       //获取记录总数 
       result.last(); 
       intRowCount = result.getRow();    //记算总页数 
       intPageCount = (intRowCount+intPageSize-1) / intPageSize;    //调整待显示的页码 
       if(intPage>intPageCount) intPage = intPageCount; 
       %>
    <h1><%=temp%>表</h1>
    <form name='form1' method='post' action=redirect.jsp?ID=<%=id%> onSubmit="return checkNO()">  
      <table width="746" height="28" border="0" align="left">
        <tr>
          <td width="76">&nbsp;</td>
          <td width="225">请输入货币编号:</td>
          <td width="196"><input name="curno" type="text" id="curno"></td>
          <td width="231"><input type="submit" name="Submit" value="查询" ></td>
        </tr>
      </table>
      <p>&nbsp;</p>
    </form><form name='form2' method='post' action=view.jsp?ID=<%=id%> onSubmit="return checkPG()">
      <table width="746" height="28" border="0" align="left">
        <tr>
          <td width="76">&nbsp;</td>
          <td width="225">请输入页码(如:1,2,3)</td>
          <td width="198"><input name="page" type="text" id="page"></td>
          <td width="229"><input type="submit" name="Submit" value="查询" ></td>
        </tr>
      </table>
      <p>&nbsp;</p>
    </form>
    <p>&nbsp;</p><table width=80% border="1" bgcolor="#0099CC">
    <tr bgcolor="#CC6633" bordercolor="#990066">
    <td>货币编号</td><td>货币名称</td><td>发行时间</td><td>删除</td><td>更改</td>
    </tr><%  //while(result.next())
       if(intPageCount>0){ 
      //将记录指针定位到待显示页的第一条记录上 
      result.absolute((intPage-1) * intPageSize + 1);   //显示数据 
      i = 0; 
      while(i<intPageSize && result.next())  
      {String mid,mname,mnub,mpti;
              mid=result.getString("ID");
              mname=result.getString("CurName");
              mnub=result.getString("CurNO");
              mpti=result.getString("PTime");
              
    out.println("<tr bordercolor=#990066>");
    out.println("<td>"+mnub+"</td>");
    out.println("<td>"+mname+"</td>");
    out.println("<td>"+mpti+"</td>");
    out.println("<td><a href='delete.jsp?ID="+mid+"&Type="+request.getParameter("ID")+"' onclick='return check();'>删除</a>");
     if(id.intern()=="1".intern())
      {
    out.println("<td><a href='zggb.jsp?ID="+mid+"'>更改</a>");
      }
      else if(id.intern()=="2".intern())
      {
    out.println("<td><a href='mghb.jsp?ID="+mid+"'>更改</a>");
      }
      else if(id.intern()=="3".intern())
      {
    out.println("<td><a href='gjdhb.jsp?ID="+mid+"'>更改</a>");
      }
      else if(id.intern()=="4".intern())
      {
    out.println("<td><a href='zgpz.jsp?ID="+mid+"'>更改</a>");
      }
      else if(id.intern()=="5".intern())
      {
    out.println("<td><a href='zggp.jsp?ID="+mid+"'>更改</a>");
      }
      else if(id.intern()=="6".intern())
      {
    out.println("<td><a href='rmb.jsp?ID="+mid+"'>更改</a>");
      }
      else if(id.intern()=="7".intern())
      {
    out.println("<td><a href='gathb.jsp?ID="+mid+"'>更改</a>");
      }
      else if(id.intern()=="8".intern())
      {
    out.println("<td><a href='dzhb.jsp?ID="+mid+"'>更改</a>");
      }
      else if(id.intern()=="9".intern())
      {
    out.println("<td><a href='wghb.jsp?ID="+mid+"'>更改</a>");
      }
      else if(id.intern()=="10".intern())
      {
    out.println("<td><a href='jnb.jsp?ID="+mid+"'>更改</a>");
      }
      else if(id.intern()=="11".intern())
      {
    out.println("<td><a href='gdhb.jsp?ID="+mid+"'>更改</a>");
      }
             else if(id.intern()=="12".intern())
      {
    out.println("<td><a href='mqzb.jsp?ID="+mid+"'>更改</a>");
      }
    out.println("</tr>");
          // result.next(); 
           i++;
        }//while
     }//if
      
      result.close();
      con.closeConnection();%>
    </table>
    第<%=intPage%>页 共<%=intPageCount%>页 
    <%if(intPage>1){%><a href="view.jsp?page=<%=intPage-1%>&ID=<%=id%>">上一页</a><%}%><%if(intPage<intPageCount){%><a href="view.jsp?page=<%=intPage+1%>&ID=<%=id%>">下一页 
    </a><%}%> 
    </center>
    </body>
    </html>
    <script language="javascript">
    function check()
    {
       return window.confirm("真的要删除?");}
    </script>