基于jsp web通用分页

<%@tag import="com.entity.PageModel"%>
<%@tag pageEncoding="UTF-8" %>
<!-- 提交到那里 -->
<%@attribute required="true" name="towhere" rtexprvalue="true" type="java.lang.String" %>
<!-- 表的列名 -->
<%@attribute required="true" name="columtitle" rtexprvalue="true" type="java.lang.String" %>
<!--分页的数据  -->
<%@attribute required="true" name="pagemodel_info" rtexprvalue="true" type="com.entity.PageModel" %>
<!-- 操作 下面的去哪里  记住下面两个要同时存在  -->
<%@attribute required="false" name="toservlet" rtexprvalue="true" type="java.lang.String" %>
<%@attribute required="false" name="caozuoinfo" rtexprvalue="true" type="java.lang.String" %>
<!-- 传参情况 记住下面两个要同时存在 -->
<%@attribute required="false" name="param_keys" rtexprvalue="true" type="java.lang.String" %>
<%@attribute required="false" name="params__values" rtexprvalue="true" type="java.lang.String" %>
  
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<style type="text/css">
#mytable {
width: 100%;
padding: 0;
border:1px solid #F3FAFF;
margin: 0px;
font-family:"微软雅黑";
font-size:14px;
}
#mytable tr{
    border-collapse:collapse;
}
#mytable td{
border:1px solid #F3FAFF;
padding-left:5px;
}
#mytablesd {
width: 100%;
padding: 0;
border:1px solid #F3FAFF;
margin: 0px;
font-family:"微软雅黑";
font-size:14px;
}
#mytablesd tr{
    border-collapse:collapse;
    text-align: center;
}
caption {
padding: 0 0 5px 0;
width: 700px;
font: italic 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
text-align: right;
}
</style>

<form name="form_lilin" method="post" action="${towhere}">
<table id="mytable">
<tr>
          <c:forTokens items="${columtitle }" delims="," var="a">
          <td>${a }</td>          
          </c:forTokens>
</tr>
<c:forEach var="a" items="${pagemodel_info.list_info }" varStatus="aa">
<tr>
       <c:forTokens items="${ pagemodel_info.list_info_properties }" delims="," var="b">
          
          <c:if test="${fn:contains(b,'[')  }">
                 
                  <c:forTokens items="${fn:substring(b,fn:indexOf(b,'[')+1,fn:length(b)-1 ) }" delims=";" var="c">
                       
                        <c:if test="${a[ fn:substring(b,0,fn:indexOf(b,'[') )] == fn:substring(c,0,fn:indexOf(c,':') )  }">
                                   <td>${fn:substring(c,fn:indexOf(c,':')+1,fn:length(c) ) }</td>
                        </c:if>
                  </c:forTokens>
          </c:if>
           <c:if test="${!fn:contains(b,'[')  }">
                  <td>${a[b] }</td>
          </c:if>
       </c:forTokens>
      
       <!-- 添加删除 等之类的 -->
       <c:if test="${ !empty toservlet }">
         <td>
              <c:forTokens items="${caozuoinfo }" delims="," var="g" varStatus="gg">
                       <a href="${ toservlet}?op=caozuoinfo_${gg.index}&id=${a[fn:substring(pagemodel_info.list_info_properties,0,fn:indexOf(pagemodel_info.list_info_properties,',') ) ]}">${g }</a>&nbsp;&nbsp;
              </c:forTokens>
         </td>        
       </c:if>
      
</tr> 
</c:forEach>

<tr align="center">
    <td colspan="${fn:length( fn:split(columtitle, ',')  ) }">
     
      一共<font color="red">${pagemodel_info.rowcount  }</font>条&nbsp;&nbsp;
      每页显示<font color="red">${pagemodel_info.rowsize }</font>条&nbsp;&nbsp;
       现在是第<font color="red">${pagemodel_info.pagenow }</font>/<font color="red">${pagemodel_info.pagesize }</font>页&nbsp;&nbsp;

<script type="text/javascript">
      function lilina_click(a){ 
             document.getElementById("lilin_pageno").value=a.attributes["va"].value;
             document.form_lilin.submit();
      }
     
     function lilina_tiao(){
    var val = document.getElementById("topagenos").value;
       var check =/^[0-9]*$/;
       if(val==""||check.test(val)==false){
         alert("使用["+val+"]跳转失败!请检查!!!");
         document.getElementById("a").value = "";
         return;
       }
         document.getElementById("lilin_pageno").value=val;
         document.form_lilin.submit(); 
  }
</script>
      
       <a  va="${pagemodel_info. startpagenum}" onclick="lilina_click(this)">首页</a>&nbsp;&nbsp;
       <a  va="${pagemodel_info. uppagenum  }" onclick="lilina_click(this)">上一页</a>&nbsp;&nbsp;
       <a  va="${pagemodel_info. downpagenum }" onclick="lilina_click(this)">下一页</a>&nbsp;&nbsp;
       <a  va="${pagemodel_info. endpagenum}" onclick="lilina_click(this)">尾页</a>&nbsp;&nbsp;
       <input type="text" id="topagenos" maxlength="6" size="3" /><a onclick="lilina_tiao()">跳转</a>
      
       <c:if test="${! empty param_keys && !empty params__values }">
               <c:forTokens items="${param_keys }" delims="," var="a" varStatus="aa">
                    <c:forTokens items="${params__values }" delims="," var="b" varStatus="bb">
                           <c:if test="${aa.index==bb.index }">
                                  <input type="hidden" name="${a }" value="${b}"/>
                           </c:if>
                    </c:forTokens>
               </c:forTokens>
       </c:if>
      
      
    </td>
</tr>
</table>
<input type="hidden" id="lilin_pageno" name="pageno" value="">
</form>
 

--测试
<%@page import="com.dao.BaseDao"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@taglib prefix="lilin" tagdir="/WEB-INF/tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'MyJsp.jsp' starting page</title>

  </head>
 
  <body>
        <%
         BaseDao b = new BaseDao();
         String as = request.getParameter("pageno");
        
        System.out.print("李林:"+request.getParameter("ai"));
        
        if( as ==null){
           request.setAttribute("a",b.queryPageModel(1, 2, "id,name,passWord,sex[0:男;1:女;2:未知]",false, "from Admin order by id desc "));
       }else{
        request.setAttribute("a",b.queryPageModel(Integer.parseInt(as), 2, "id,name,passWord,sex[0:男;1:女;2:未知]",false, "from Admin order by id desc "));
      }
         %>
  <lilin:Myfenye columtitle="编号,姓名,密码,性别,操作" caozuoinfo="删除,修改" toservlet="a.action"  param_keys="ai" params__values="爱你"  towhere="MyJsp.jsp" pagemodel_info="${a }"></lilin:Myfenye>    
      
  </body>

 

你可能感兴趣的:(jsp)