首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

JSP页面实现带导航条的数据分页?解决办法

2012-05-20 
JSP页面实现带导航条的数据分页?如何实现如下的分页导航条?HTML code %@page contentTypetext/htmlcha

JSP页面实现带导航条的数据分页?
如何实现如下的分页导航条?



HTML code
 <%@page contentType="text/html;charset=GBK" language="java" %> 
<%@ include file="/pub/taglibs.jsp"%>
<%@ page import ="java.util.Vector" %>
<%@ page import ="com.dljt.action.sysframe.FuncModel" %>
<%@ page import="com.dljt.util.*"%>
<%@ page import="java.sql.*"%>
<jsp:useBean id="keyUserSessionModel" type="com.dljt.action.sysframe.UserSessionModel" scope="session"> </jsp:useBean>
<jsp:useBean id="jiaoCaiJiChuXinXiListdata" type="java.util.Vector" scope="request"> </jsp:useBean>
<%
    com.dljt.pub.tag.sql.TagDAO myTagDAO = new com.dljt.pub.tag.sql.TagDAO();
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>图书管理 </title>
<link href=" <%= request.getContextPath() %>/include/style.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="EFF2F4" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" >
<%@ include file="/sysframe/tsheader.jsp" %>
<table width="960" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td background=" <%= request.getContextPath() %>/image/bj01.gif">
            <%
            //定义全局变量实现分页
            int pageSize=5; //分页每页记录数
            int rowCount;    //总的记录数
            int pageCount;  //总的页数
            int pageNow=0;  //希望显示第几页
           
            String s_pageNow=request.getParameter("pageNow");//从页面得到页数
            if(s_pageNow==null)
            { pageNow=1; }
            else
            {
            pageNow=Integer.parseInt(s_pageNow);
              if(pageNow <1)
              { pageNow=1; }
            }
           
            Vector rs=jiaoCaiJiChuXinXiListdata;
            rowCount=rs.size() ;  //得到总的记录数
            if(rowCount%pageSize==0){
                pageCount=rowCount/pageSize; //得到总页数
            }else{
              pageCount=rowCount/pageSize+1;
            }
            %>       
    <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
        <td width="182" valign="top" background="/image/leftbj02.gif"> <%@ include file="/sysframe/tsleft.jsp" %> </td>
        <td valign="top">


        <table width="99%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
        <td>
        <html:form action="/JiaoCaiJiChuXinXi_Action.do" method="post">
        <input type="hidden" name="xxb_jcid">
        <input type="hidden" name="type"> 
                    <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
                        <tr>
                            <td class="titleTxt02">
                                <br>                               
                                <fieldset>
                                <legend>查询条件 </legend>
                                <table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
                                      <tr>
                                          <td height="5"> </td>
                                    </tr>
                                      <tr>           
                                        <td width="20%" nowrap="nowrap" >&nbsp;&nbsp;教材名称:&nbsp;&nbsp; <html:text property="xxb_jcmc" size="30"/> </td>                                                                                     
                                        <td width="10%" align="center" >
                                        <input name="Submit23" type="submit" class="button" value=" 查询 " onclick='addEvent("select");'>&nbsp;&nbsp;                                   
                                        <input type="button" value=" 新增教材 " onclick='addEvent("add");' > </td>


                                      </tr>
                                      <tr>
                                          <td height="5"> </td>
                                    </tr>
                                </table>
                                </fieldset>                                       
                            </td>
                        </tr>   
                    </table>   
          </html:form>
          </td>
          </tr> 
                    <tr>
                    <td>             
                    <table align="center" >
                    <tr> <td align="center"  class="titleText" height="30">教材基础信息 </td> </tr>
                    </table>             
                    </td>
                    </tr>
                    <tr>
                    <td>
                    <table width="98%" border="0" align="center" cellpadding="1" cellspacing="1" class="tableStyle01">                     
                      <tr>
                      <td width="20%" align="center" nowrap class="TDstyle02"> <strong>教材名称 </strong> </td>               
                      <td width="20%" align="center" nowrap class="TDstyle02"> <strong>出 版 社 </strong> </td>                 
                        <td width="10%" align="center" nowrap class="TDstyle02"> <strong>预存数量 </strong> </td>
                        <td width="10%" align="center" nowrap class="TDstyle02"> <strong>库存数量 </strong> </td>
                        <td width="10%" align="center" nowrap class="TDstyle02"> <strong>详&nbsp;&nbsp;&nbsp;&nbsp;细 </strong> </td>


                        <td width="10%" align="center" nowrap class="TDstyle02"> <strong>入库明细 </strong> </td>
                        <td width="10%" align="center" nowrap class="TDstyle02"> <strong>出库明细 </strong> </td>
                        <td width="10%" align="center" nowrap class="TDstyle02"> <strong>操&nbsp;&nbsp;&nbsp;&nbsp;作 </strong> </td>
                      </tr>                             
                      <%                       
                        int num1 = 0;
                        int num2 = 0;   
                        String style = "";                   
                        for(int j=0; j <jiaoCaiJiChuXinXiListdata.size(); j++ ){
                        String[] rowdata = (String[])jiaoCaiJiChuXinXiListdata.elementAt(j); 
                        num1 = Integer.parseInt(new String (rowdata[6]));
                        num2 = Integer.parseInt(new String (rowdata[8]));
                        if(num1 > num2){
                        style = "color:red;font-weight:bold";
                        }
                        else{
                        style="";
                        } 
                            if (j <pageSize*pageNow && j>=pageSize*(pageNow-1))
                          {                                     
                      %>                                                   
                      <tr>
                      <td height="30" align="center" class="TDstyle01"> <%= rowdata[1] %> </td>
                      <td height="30" align="center" class="TDstyle01"> <%= rowdata[2] %> </td>
                      <td height="30" align="center" class="TDstyle01"> <%= rowdata[6] %> </td>


                      <td height="30" align="center" class="TDstyle01" style=" <%=style%>"> <%= rowdata[8] %> </td>
                      <td height="30" align="center" class="TDstyle01"> <a href='javascript:linkEvent(" <%=rowdata[0]%> ","selectinfo")' class="link01">详细 </a> </td>
                      <td height="30" align="center" class="TDstyle01"> <a href=" <%= request.getContextPath() %>/JiaoCaiRuKuList_Action.do?data1= <%=rowdata[0] %>" class="link01">详情 </a> </td>
                      <td height="30" align="center" class="TDstyle01"> <a href=" <%= request.getContextPath() %>/JiaoCaiChuKuList_Action.do?data2= <%=rowdata[0] %>" class="link01">详情 </a> </td>
                      <td height="30" align="center" class="TDstyle01"> <a href='javascript:linkEvent(" <%=rowdata[0]%> ","update")' class="link01">修改 </a>| <a href='javascript:linkEvent(" <%=rowdata[0]%>","delete")' class="link01" onclick="{if(confirm('删除教材基础信息将无法再恢复,你真的要删除吗?')){return true;}return false;}">删除 </a> </td>                     
                      </tr>                                                     
                      <%
                        }
                        }
                      %>       
                    </table>     
                    </td>
                    </tr>
                    <tr>
                    <td align="center" class="TDstyle01">
                    <%                 
                    //当前页
                    out.println("第"+pageNow+"页");
                    //上一页
                    if(pageNow!=1){
                      out.println(" <a href=JiaoCaiJiChuXinXi_Action.do?pageNow="+(pageNow-1)+" class='link01'>[上一页] </a>");
                    }
                    //下一页
                    if(pageNow!=pageCount){


                      out.println(" <a href=JiaoCaiJiChuXinXi_Action.do?pageNow="+(pageNow+1)+">[下一页] </a>");
                    }
                    //显示超链接
                    for(int j=1;j <=pageCount;j++){
                        out.println(" <a href=JiaoCaiJiChuXinXi_Action.do?pageNow="+j+">["+j+"] </a>");
                    }
                    //共页
                    out.println("共"+pageCount+"页");
                    %>                                       
                    </td>
                    </tr>
          </table> </td>
      </tr>
</table>
<%@ include file="/tail.jsp" %>
</body>
</html>



[解决办法]
图片看得这么眼熟,原来是我的,呵呵。原文地址:
http://howsun.blog.sohu.com/90707791.html

楼主不是已经在JSP中做好分页了吗?现在有什么问题?
建议使用MVC模式吧,这种代码只有谁写的谁去看。
[解决办法]
用pager-taglib的jar包吧 能实现那种效果的
http://blog.csdn.net/lgm277531070/archive/2009/12/02/4926186.aspx

热点排行