我思故我强

简单的jsp控制分页


<%
 //分页显示
 int num = 0;
 int countall = infolist.size();//总数
 int pageSize = 28;//每页数量
 int pageCount;//总共页数
 int pageNo = 1;//当前页号
 int mixNum;   //当前页数据开始号
 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("请输入页数");
 }
 else if(checkNum(document.forms.meslistForm.textfield.value)){
  window.location.href="?pageNo="+document.forms.meslistForm.textfield.value;
 }else{
  alert("请输入数字。");
 }
 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循环下标用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;首页</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <%
                     }else{
                    %> &nbsp;首页&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;前一页</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <%
                     }else{
                    %> &nbsp;前一页&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;后一页</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <%
                     }else{
                    %> &nbsp;&nbsp;后一页&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;尾页</a> <%
                     }else{
                    %> &nbsp;&nbsp;尾页 <%
                     } 
                    %>
    <td width="26%" align="center" valign="middle" class="word">共<%=pageCount%>页&nbsp;第<%=pageNo%>页&nbsp;
    跳转</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 李云泽 阅读(258) 评论(0)  编辑  收藏 所属分类: J2EEJava代码


只有注册用户登录后才能发表评论。


网站导航: