jsp 簡單一實例分頁代碼

來源:互聯網
上載者:User

jsp 簡單一實例分頁代碼

<%
int pageSize=10;
int showPage=1;
int recCount=0;
int pageCount=0;
String SqlArticle;
String toPage = request.getParameter("page");
SqlArticle="Select * from hl_news where smallname='"+csmallname+"' order by

times DESC";
ResultSet RsArticle=stmt1.executeQuery(SqlArticle);
 if(RsArticle.next()) {
 RsArticle.last();
 recCount=RsArticle.getRow();
 pageCount=((recCount%pageSize)==0?(recCount/pageSize):

(recCount/pageSize)+1);
 if(toPage!=null)
  showPage=Integer.parseInt(toPage);
  RsArticle.absolute((showPage-1)*pageSize+1);
 for(int i=1;i<=pageSize;i++){
  int NID=RsArticle.getInt("ID");
  String ttt = RsArticle.getString("times");
 %> 
                          <tr>
                            <td align="middle" width="18"><img height="5"

src="images/kuang_10.gif" width="5" /></td>
                            <td class="riqi_1" align="middle"

width="92"><span class="f-14-hui" style="width:100px;"><%=ttt%> |

</span></td>
                            <td width="463" height="30" align="left"

class="tong_1"><a class="wen_4" href="newshows.jsp?id=<%=NID%>"

target="_blank"><%=RsArticle.getString("title")%></a></td>
                            <td width="56" class="wen_4">[<a 

href="newshows.jsp?id=<%=NID%>" target="_blank">查看</a>]</td>
                          </tr>
                          <tr>
                            <td background="images/kuang_09.gif" colspan="4"

height="2"></td>
                          </tr>
<%
 if(!RsArticle.next())
  break;
 }
}
%>
                        </tbody>
                    </table></td>
                    <td width="4"
                                background="images/kuang_05.gif"></td>
                  </tr>
                  <tr>
                    <td width="4" height="4"><img height="4"
                                src="images/kuang_06.gif"
                                width="4" /></td>
                    <td background="images/kuang_07.gif"
                                height="4"></td>
                    <td width="4" height="4"><img height="4"
                                src="images/kuang_08.gif"
                                width="4" /></td>
                  </tr>
                </tbody>
              </table>
                <table align="center" border="0">
                  <form onsubmit="document.location =

'http://www.intgz.com/news.asp?cid=1&amp;Page='+ this.page.value;return

false;" method="get">
                    <tbody>
                      <tr>
                        <td align="right"> <% if(showPage>1){ %><a class='f

-12-black' href='news.jsp?id=<%=cid %>&smallname=<%=csmallname%>&page=1'>首

頁</a> <% } if (showPage>1) { %><a class='f-12-black' href='news.jsp?id=<%

=cid %>&smallname=<%=csmallname%>&page=<%= showPage-1 %>'>上一頁</a>&nbsp;<%

} if (showPage<pageCount) { %>&nbsp;<a class='f-12-black' href='news.jsp?

id=<%=cid %>&smallname=<%=csmallname%>&page=<%= showPage+1 %>'>下一頁

</a>&nbsp;<% } %>&nbsp;<% if(showPage<pageCount){ %><a class='f-12-black'

href='news.jsp?id=<%=cid %>&smallname=<%=csmallname%>&page=<%=pageCount %>'>

尾頁</a>&nbsp;<%       } %> 頁次:<%=showPage %

>/<%=pageCount%>頁 共有<%=recCount%>條記錄 <a class='f-12-black'>轉到第

<select name='sel_page' onChange='javascript:location=this.options

[this.selectedIndex].value;'><%  for(int i=1;i<=pageCount;i++){  %> <option

value='news.jsp?id=<%=cid %>&smallname=<%=csmallname%>&page=<%=i %>' <% if

(i==showPage){ %>selected <% } %>><%=i %></option><% } %></select>頁

</a></td>
                      </tr>
                    </tbody>
                  </form>
                        </table></td>
                    </tr>
              </table></td>
            </tr>
          </table></td>
      </tr>
    </table></td>
<%
 RsArticle.close();
 }
 Rs6.close();
}
stmt1.close();
%>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.