plugins

来源:互联网 发布:chart.js官方文档 编辑:程序博客网 时间:2024/04/29 03:50

 http://hi.baidu.com/rxt_gogle/blog/item/13c073159e498ad2a7ef3fb9.html

原创分页“插件”——JSTL版

最近,自己做一个分页的“插件”。说他是插件,是因为,自己认为比较用通用性吧。

要不把这样的分页程序写在JSP界面上会觉得很乱。而用的时候,直接 <jsp:include flush="true" page=""/>就可以了。

好,那这次做的是JSTL版本的。

插件如下:

<c:if test="${page==1}">

               <button disabled="disabled">首页</button>&nbsp;

               <button disabled="disabled">上一页</button>&nbsp;

            </c:if>

           

            <!--关键字为空 -->

         <c:if test="${empty keyWord}">

            <c:if test="${page>1}">

               <button onclick="myForword(1,'')">首页</button>&nbsp;

               <button onclick="myForword(${page-1 },'')">上一页</button>&nbsp;

            </c:if>

            <c:if test="${page==totalPage}">

               <button disabled="disabled">下一页</button>&nbsp;

               <button disabled="disabled">尾页</button>&nbsp;

            </c:if>

            <c:if test="${page<totalPage}">

               <button onclick="myForword(${page+1 },'')">下一页</button>&nbsp;

               <button onclick="myForword(${totalPage },'')">尾页</button>&nbsp;

            </c:if>

           

            <form action="EmpServlet" method="post" name="form2">

            跳转到

               <select name="page" onchange="document.form2.submit()">

                  <c:forEach var="i" begin="1" end="${totalPage}" step="1">

                      <option value=${i } <c:if test="${i==page }">selected</c:if> >${i }</option>

                  </c:forEach>

              </select>

           页

            </form>

        </c:if>

       

        <!--关键字不为空 -->

        <c:if test="${not empty keyWord}">

            <c:if test="${page>1}">

               <button onclick="myForword(1,'${keyWord }')">首页</button>&nbsp;

               <button onclick="myForword(${page-1 },'${keyWord }')">上一页</button>&nbsp;

            </c:if>

            <c:if test="${page==likePage}">

               <button disabled="disabled">下一页</button>&nbsp;

               <button disabled="disabled">尾页</button>&nbsp;

            </c:if>

            <c:if test="${page<likePage}">

               <button onclick="myForword(${page+1 },'${keyWord }')">下一页</button>&nbsp;

               <button onclick="myForword(${likePage },'${keyWord }')">尾页</button>&nbsp;

            </c:if>

            <form action="EmpServlet" method="post" name="form3">

              <input type="hidden" name="keyWord" value="${keyWord }"> <!-- 关键 -->

            跳转到

               <select name="page" onchange="document.form3.submit()">

                  <c:forEach var="i" begin="1" end="${likePage}" step="1">

                      <option value=${i } <c:if test="${i==page }">selected</c:if> >${i }</option>

                  </c:forEach>

              </select>

           页

            </form>

        </c:if>

 

<!--关键字为空 -->

      <c:if test="${empty keyWord}">

         <h2>共<font color="red">${totalCount }</font>条记录</h2>

         <h2>第<font color="red">${page }</font>页&nbsp;共<font color="red">${totalPage }</font>页</h2>

      </c:if>

      <!--关键字不为空 -->

      <c:if test="${not empty keyWord}">

         <h2>共<font color="red">${likeCount }</font>条记录</h2>

         <h2>第<font color="red">${page }</font>页&nbsp;共<font color="red">${likePage }</font>页</h2>

      </c:if>
 


执行跳转的JavaScript代码如下:

 

      //跳转

      function myForword(page,keyWord)

      {

         location.href="EmpServlet?page="+page+"&keyWord="+keyWord;

      }
 

 

 

介绍完毕,前台使用,仅供参考。

原创粉丝点击