我思故我強(qiáng)

          簡(jiǎn)單的jsp控制分頁(yè)


          <%
          ?//分頁(yè)顯示
          ?int num = 0;
          ?int countall = infolist.size();//總數(shù)
          ?int pageSize = 28;//每頁(yè)數(shù)量
          ?int pageCount;//總共頁(yè)數(shù)
          ?int pageNo = 1;//當(dāng)前頁(yè)號(hào)
          ?int mixNum;?? //當(dāng)前頁(yè)數(shù)據(jù)開(kāi)始號(hào)
          ?int maxNum;
          ?
          ?String pNO = request.getParameter("pageNo");

          ?if((pNO != null) && (!pNO.equals(""))){

          ??pageNo=Integer.parseInt(pNO);
          ?}

          ?if (countall > pageSize) {
          ??if ((countall / pageSize) * pageSize < countall) {
          ???pageCount = (countall / pageSize) + 1;
          ??}
          ??else{
          ???pageCount = (countall / pageSize);
          ??}
          ?}
          ?
          ?else if (countall / pageSize == 1) {
          ??pageCount = 1;
          ?}
          ?else {
          ??pageCount = 1;
          ?}

          ?if (pageNo >= pageCount) {
          ??pageNo = pageCount;
          ?}
          ?else if (pageNo < 1) {
          ??pageNo = 1;
          ?}
          ????
          ????
          ?mixNum = (pageNo-1) * pageSize;
          ?maxNum = pageNo*pageSize;
          ?
          ?if((mixNum + pageSize) > countall){
          ??maxNum = countall;
          ?}
          ?else{
          ??maxNum = mixNum+pageSize;
          ?}
          %>
          ---------------------------------------------------------------------------------------------
          <html>
          <head>
          <script language="JavaScript" type="text/JavaScript">
          function check(){
          ?if(Jtrim(document.forms.meslistForm.textfield.value)==""){
          ??alert("請(qǐng)輸入頁(yè)數(shù)");
          ?}
          ?else if(checkNum(document.forms.meslistForm.textfield.value)){
          ??window.location.href="?pageNo="+document.forms.meslistForm.textfield.value;
          ?}else{
          ??alert("請(qǐng)輸入數(shù)字。");
          ?}
          ?document.forms.meslistForm.textfield.value = "";
          ?document.forms.meslistForm.textfield.select();
          }
          function checkNum(str){
          return str.match(/\D/)==null;
          }

          function Jtrim(str)
          {

          ??????? var i = 0;
          ??????? var len = str.length;
          ??????? if ( str == "" ) return( str );
          ??????? j = len -1;
          ??????? flagbegin = true;
          ??????? flagend = true;
          ??????? while ( flagbegin == true && i< len)
          ??????? {
          ?????????? if ( str.charAt(i) == " " )
          ??????????????? {
          ????????????????? i=i+1;
          ????????????????? flagbegin=true;
          ??????????????? }
          ??????????????? else
          ??????????????? {
          ??????????????????????? flagbegin=false;
          ??????????????? }
          ??????? }

          ??????? while? (flagend== true && j>=0)
          ??????? {
          ??????????? if (str.charAt(j)==" ")
          ??????????????? {
          ??????????????????????? j=j-1;
          ??????????????????????? flagend=true;
          ??????????????? }
          ??????????????? else
          ??????????????? {
          ??????????????????????? flagend=false;
          ??????????????? }
          ??????? }

          ??????? if ( i > j ) return ("")

          ??????? trimstr = str.substring(i,j+1);
          ??????? return trimstr;
          }</script>
          </head>


          <body>
          <%
          ?for(int i=mixNum;i<maxNum;i++){
          ?//此處用list循環(huán)下標(biāo)用i
          ?}????? ???
          %>

          ?

          ?

          ?

          ?


          ?<table align="center" width="100%" border="0" cellspacing="0" cellpadding="0">
          ???<tr>
          ????<td width="4%" height="27" align="center" valign="middle"
          ?????class="word">&nbsp;</td>
          ????<td width="56%" align="center" valign="middle" class="word"><img
          ?????src="<%=path%>/images/pagination/list_home.gif" width="13"
          ?????height="13">&nbsp; <%
          ??????if (pageNo > 1) {
          ?????%> <a href="?pageNo=1">&nbsp;首頁(yè)</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          ????<%
          ??????????????????? ?}else{
          ??????????????????? %> &nbsp;首頁(yè)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <%
          ??????????????????? ?}
          ??????????????????? %> <img src="<%=path%>/images/pagination/list_pre.gif"
          ?????width="13" height="13"> <%
          ??????if (pageNo > 1) {
          ?????%> <a href="?pageNo=<%=(pageNo-1)%>">&nbsp;前一頁(yè)</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          ????<%
          ??????????????????? ?}else{
          ??????????????????? %> &nbsp;前一頁(yè)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <%
          ??????????????????? ?}
          ??????????????????? %> <img
          ?????src="<%=path%>/images/pagination/list_next.gif" width="13"
          ?????height="13"> <%
          ??????if (pageCount>pageNo) {
          ?????%> <a href="?pageNo=<%=(pageNo+1)%>">&nbsp;&nbsp;后一頁(yè)</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          ????<%
          ??????????????????? ?}else{
          ??????????????????? %> &nbsp;&nbsp;后一頁(yè)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <%
          ??????????????????? ?}?
          ??????????????????? %> <img src="<%=path%>/images/pagination/list_end.gif"
          ?????width="13" height="13"> <%
          ??????if (pageCount>pageNo) {
          ?????%> <a href="?pageNo=<%=(pageCount)%>">&nbsp;&nbsp;尾頁(yè)</a> <%
          ??????????????????? ?}else{
          ??????????????????? %> &nbsp;&nbsp;尾頁(yè) <%
          ??????????????????? ?}?
          ??????????????????? %>
          ????<td width="26%" align="center" valign="middle" class="word">共<%=pageCount%>頁(yè)&nbsp;第<%=pageNo%>頁(yè)&nbsp;
          ????跳轉(zhuǎn)</td>
          ????<td width="4%" align="center" valign="middle" class="word"><input
          ?????name="textfield" type="text" class="input" size="1"></td>
          ????<td width="6%" align="center" valign="middle" class="word"><a
          ?????href="javascript:check()"><img
          ?????src="<%=path%>/images/pagination/go.gif" border="0" width="18"
          ?????height="18"></a></td>

          ????<td width="4%" align="left" valign="middle" class="word">&nbsp;</td>
          ???</tr>
          ??</table></body>??
          </html>

          posted on 2007-08-03 10:55 李云澤 閱讀(270) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): J2EEJava代碼

          主站蜘蛛池模板: 东台市| 松原市| 秦皇岛市| 曲靖市| 台北县| 简阳市| 城步| 宁河县| 武平县| 邻水| 土默特右旗| 诏安县| 建昌县| 保山市| 古田县| 尼木县| 石河子市| 广平县| 鹿邑县| 梓潼县| 昌江| 渭源县| 昌吉市| 仲巴县| 团风县| 鄂尔多斯市| 湾仔区| 普定县| 德保县| 肥东县| 平谷区| 诸城市| 威宁| 定陶县| 当涂县| 昭觉县| 重庆市| 满洲里市| 邛崃市| 从化市| 顺平县|