我想把循环出来的结果集放到一个table中,然而我想给这个表里的数据加一个序号从一开始,有分页时序号也一直序下去,比如第一页有十条数据,序号是到十,第二页就是从十一开始的序号,即使删除了任何一条数据对序号都不会有影响,还是从一开始 依次类推。

解决方案 »

  1.   

    这个我刚弄了下,还是很好解决的。不知道你是如何做分页的
    code=Java]
    <table class="protab">
          <tr>
            <th style="white-space:nowrap;" colspan="2">序号</th>
            <th style="white-space:nowrap;">产品名字</th>
          </tr>
     <logic:present name="List">
           <logic:iterate id="pList" name="List" indexId="nb">
             <td >
    <!--   *************************** -->
                <logic:present name="pager">
                   <logic:greaterThan value="1" name="pager">
                ${(pager.currentPage-1)*3+nb+1}
                   </logic:greaterThan>
                </logic:present>
    <!--   *************************** -->
             </td>
             <td >${plist.productNm}</td>
    [/code]
    可能说得不是很明白,涉及到很多分页参数!其中indexId是循环标记<logic:iterate >里的一个参数,默认为0(nb+1就是第一条为1),pager.currentPage为当前页码(第1页,2页...),3为每页3条记录。方法大概是这样,就是做个简单计算。主要是你要取出当前是第几页(如参数pager.currentPage)
      

  2.   

    jsp就 struts标签,JSTL好用吧,现在大家都推荐用。
    不知道你是怎么在table里循环出来的。建议学习jstl标签吧
      

  3.   

    <table width="100%" border="1" cellspacing="0" cellpadding="0">
      <tr>
        <th height="24" background="../images/main_title_02.gif" scope="col">序号</th>
        <th background="../images/main_title_02.gif" scope="col">标题</th>
        <th background="../images/main_title_02.gif" scope="col">类型</th>
        <th background="../images/main_title_02.gif" scope="col">网址</th>
        <th background="../images/main_title_02.gif" scope="col">操作</th>
      </tr> <%while(rsf.next()){ %>
      <tr>
     
        <td></td>
        <td><a href="<%=rsf.getString("favorite_url") %>" title="<%=rsf.getString("favorite_title") %>"><%=rsf.getString("favorite_title").length()>5?rsf.getString("favorite_title").substring(0,5)+"...":rsf.getString("favorite_title") %></a></td>
        <td><%=rsf.getString("favorite_type_name") %></td>
        <td><a href="<%=rsf.getString("favorite_url") %>" title="<%=rsf.getString("favorite_title") %>"><%=rsf.getString("favorite_url").length()>20?rsf.getString("favorite_url").substring(0,20)+"...":rsf.getString("favorite_url") %></a></td>
        <td>
        编辑&nbsp;&nbsp;删除
        </td>  </tr>    <%} %>
    </table>
      

  4.   

    [Quote=引用 7 楼 jianan19860 的回复:]
    <table width="100%" border="1" cellspacing="0" cellpadding="0">
        <tr>
          <th height="24" background="../images/main_title_02.gif" scope="col">序号 </th>
          <th background="../images/main_title_02.gif" scope="col">标题 </th>
          <th background="../images/main_title_02.gif" scope="col">类型 </th>
          <th background="../images/main_title_02.gif" scope="col">网址 </th>
          <th background="../images/main_title_02.gif" scope="col">操作 </th>
        </tr>  <%while(rsf.next()){ %>
        <tr>      <td><%加序号处%</td>
       这里怎么加序号
      

  5.   

    可以用标签<logic:iterate > 的indexId 属性进行记录序号。当点击下一页或第几页时,通过页码与indexId的值进行计算序号的值。 
      

  6.   

    JSP里面实现分页   我是在用SQL语句实现的 插入的时候就编号好<%
    List pdList = new ArrayList();
    request.setCharacterEncoding("GBK");
    int pageid = Integer.parseInt(request.getParameter("pageid"));
    ProductDao pd = new ProductDao();
    String sql = null;
    //取得当前商品数量
    String sql1 = "select count(productID) from PRODUCT";
    int num = pd.MaxProductNum(sql1);
    int yeshu = num / 5 + 1;
    //获得当前商品列表
    if (pageid == 1 || pageid < 1) {
    pageid = 1;
    int[] b = {};
    sql = "select  TOP 5 * from PRODUCT";
    pdList = (List) pd.findAllProduct(sql, b);
    } else if (pageid > yeshu) {
    pageid = yeshu;
    int a = (pageid - 1) * 5;
    int[] b = {};
    sql = "select  TOP 5 * from PRODUCT where  productID not in (select  TOP "+ a + "  productID from PRODUCT)";
    pdList = (List) pd.findAllProduct(sql, b);
    } else if (pageid <= yeshu) {
    int a = (pageid - 1) * 5;
    int[] b = {};
    sql = "select  TOP 5 * from PRODUCT where  productID not in (select  TOP "
    + a + "  productID from PRODUCT)";
    pdList = (List) pd.findAllProduct(sql, b);
    }
    %>
      

  7.   

    我这个是一页5个商品   你写SQL语句就很好用   我写的代码很烂- -!