有关我公司后台PageDisplay分页实用工具类的详细分析!

 <form action="/manage/help_info/help_info_list.jsp" method="post" name="searchForm" class="9pt-font" id="searchForm">
  <input name="keyword" type="text" id="keyword">
<%
     typeinfoListBus TILB=new typeinfoListBus(); //获得查询所需的类型,
  out.print(TILB.getInfoTypes());
%>
   <input type="submit" name="Submit" value=" 查询 ">
</form>

String keyword=request.getParameter("keyword");//查询关键字
 if(keyword==null)
 {
     keyword="";
 }
String sql="select info_id,title as '帮助信息主题',content as '帮助信息内容' FROM help_info where title like '%"+keyword+"%'";

PageDisplay display = new PageDisplay();

调用了 public PageDisplay()
        {
                this.tableBorder="0";
                this.tableBgcolor="#dc6b0e";
                this.tableCellpadding="2";
                this.tableCellspacing="1";
                this.tableFirstRowBgcolor="#dc6b0e";
                this.tableLastRowBgcolor="#FFFFFF";
                this.tableRowcolor1="#FFFFFF";
                this.tableRowcolor2="#E0E0E0";
                this.tableAlign="center";
                this.otherArg="";

        }
display.addRowClick("1"," target=/"_self/"","eidt_help_info.jsp?info_id=");添加横向点击链接
 public boolean addRowClick(String indexID,String lable,String target)
            throws NumberFormatException
        {
                try
                {
                        java.lang.Integer test=new Integer(indexID);
                }
                catch(Exception ex)
                {
                        throw new NumberFormatException("indexID 要为整数");
                }

                String[] aClick=new String[3];
                aClick[0]=indexID;      //传递过来的参数
                aClick[1]=lable;
                aClick[2]=target;
                this.RowClick.addElement(aClick);
                return true;
        }
其中/**
         * 横向链接
         */
        Vector RowClick=new Vector();
getRowClick()方法获得之,将返回一个String[][]的数组,this.RowClick.toArray(rowClick);将Vector
换之为数组.我想一般应该是1个选项的三个String[]吧.

 display.init(request,firstno,20,sql);将传入四个参数,request是HttpServletRequest
,firstno是pageStart开始页码,20是pageSize,sql是传入要查询的SQL语句.这个函数中首先
URL是得到谁访问了此类,request.getRequestURI();另需确定真正的pageSize和pageStart因此他们可以通过参数传递过来的,并一定是来自方法.(不过一般第一次没什么?pageSize=213&pageStart=3之类的东东吧
接下来是init(        int pageStart,
            int pageSize,
            String sql)
        方法:
初始化各参数,统计记录数  this.pageSize=pageSize;
                this.pageStart=pageStart;
                this.qdSQL=sql;
this.noData 及this.totalRecord等通过RS结果可得到
if(this.totalRecord%this.pageSize>0)
                        {
                                this.totalPage=this.totalRecord/this.pageSize+1;
                        }
                        else
                        {
                                this.totalPage=this.totalRecord/this.pageSize;
                        }
得到totalPage;

//开始页数 pageStart的判断
                        if(this.pageStart<1)
                        {
                                this.pageStart=1;
                        }
                        if(this.pageStart>this.totalPage)
                        {
                                this.pageStart=this.totalPage;
                        }
                        if(this.totalPage==0)
                        {
                                this.pageStart=1;
                        }


 //开始及结束记录数编号
                        this.startRecord=(this.pageStart-1)*this.pageSize;
                        this.endRecord=this.pageStart*this.pageSize;//从第一条开始算
if(this.endRecord>this.totalRecord)
                        {
                                this.endRecord=this.totalRecord;
                        }
                        this.currentPageSize=this.endRecord-this.startRecord;
最后一页的问题……

OK!接下来:
 display.setFormAction("/servlet/com.helpinfo.editHelpInfo");

设置form的action 
        public void setFormAction(String formaction)
        {
                this.FormAction=formaction;
        }
应该是用于删除按钮吧.
最后一条是String list=display.list();
list方法返回结果字符串String:
用了一个StringBuffer类型的listString (ENV_TYPE=1为Unix+resin ,2为window2003+resin
可能是由于编写不一样,才需要判断吧)
 rs=stmt.executeQuery(mytmp);将返回结果集
可看作一张两维表
  ResultSetMetaData rsmd=rs.getMetaData();  可参考
http://www.cnjsp.org/view.jsp?column=2&id=830 动态访问数据库
   if(this.beginTableTag)是开头吗?当然是了.以下是产生在body区的代码,其中<form>上面的是和前面的jsp文件中的一样!后面才是动态生成的!

<body>
<form action="/manage/help_info/help_info_list.jsp" method="post" name="searchForm" class="9pt-font" id="searchForm">
  <input name="keyword" type="text" id="keyword">
<select name="type_id" id="type_id"><option value="1">注册与认证</option><option value="3">普通会员入门</option><option value="4">商家入门1</option><option value="5">购买指南1</option></select>
   <input type="submit" name="Submit" value=" ?é?? ">
</form>

<SCRIPT language=javascript>function formreset() { delfrm.reset();return;}</SCRIPT><form name="delfrm" method="post" action="/servlet/com.helpinfo.editHelpInfo" οnsubmit="return delit()"><table width= "100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#dc6b0e" class="pt9" align="center">
  <tr align="center" bgcolor="#dc6b0e">
    <td>帮助信息主题</td>
    <td>帮助信息内容</td>
<td> y</td>  </tr>
  <tr  bgcolor="#FFFFFF">
    <td><a href="eidt_help_info.jsp?info_id=1" target="_self">如何注册普通会员?</a></td>
    <td>sdfdsfds第一步:点击菜单“我的ECOST”,然后点击“普通会员注册通道</td>
<td><input type="checkbox" name="deleted" value="1"></td>  </tr>
  <tr hight="2" bgcolor="#dc6b0e">
   <td>   </td>
  </tr>
  <tr align="right" bgcolor="#FFFFFF">
   <td colspan="3">   </td>
  </tr>
  <tr align="center" bgcolor="#FFFFFF">
   <td colspan="3"><input name="del" type="image" src="/manage/images/del.gif" ><img src="/manage/images/reselect.gif" onClick="formreset()" style="CURSOR: hand"><img src="/manage/images/selectall.gif" onClick="selectidall()" style="CURSOR: hand"><input type="hidden" name="v1">   </td>
  </tr>
</table>
</form>  

       
</body>

原来在form=delfrm之前头部加上了一段脚本啊!formreset
<SCRIPT language=javascript>function formreset() { delfrm.reset();return;}</SCRIPT>
if(this.getShowForm())
private boolean ShowForm=true;
        private boolean titleFlag=true;
        private boolean beginTableTag=true;
        private boolean bottomRowFlag=true;
当然也为true了
加入了带method,action和οnsubmit=/"return delit()/">"
先是form->table->tr表头->tr内容(重复)->tr底边
   ResultSetMetaData rsmd=rs.getMetaData();
         columnCount=rsmd.getColumnCount(); //列数
String tmp=rsmd.getColumnName(i+1);获得下一个的列名,因为第一个是no不用,
 tmp=(tmp.equals("AuditTime"))?"审核":tmp;
判断审核用的,接下来是功能选择:

// 是否显示列表的form及删除按扭与checkbox 
  private boolean ShowForm=true;//最后有此项!
        public void setShowForm(boolean newShowForm)
        {
                this.ShowForm=newShowForm;
        }

        public boolean getShowForm()
        {
                return ShowForm;
        }
 private String FormTitle="选项";
GO ON!!!!
  for(int i=0;i<this.startRecord;i++)  // this.startRecord=(this.pageStart-1)*this.pageSize;
                        {
                                rs.next();
                        }
   //显示数据
注意的是rs前面并没有移动,现在移到开始要读的开始处。
 if(this.noData)
                        {
                                listString.append(
                                    "  <tr  bgcolor=/"#F6F6F6/">/r/n");
                                listString.append(
                                    "<td align=/"center/" colspan=/""
                                    +this.columnCount+"/">/r/n");
                                listString.append("暂时没有相关数据。");
                                listString.append("</td>/r/n");
                                listString.append("  </tr>/r/n");
                        }

 for(int ii=0;ii<this.currentPageSize;ii++)//currentPageSize为要显示的页大小。
                        {
                                rs.next();   //开始移动了哦!!!
this.currentPageSize=this.endRecord-this.startRecord;//this.endRecord是经过处理的.
外循环是记录数,那内。。是一条了哦,所以rs.next();一下
String pk=rs.getString(1);获得主键!   for(int i=2;i<=columnCount;i++)
注意前面是:
    for(int i=1;i<columnCount;i++)//i从1开始了!!
                                {
                                        String tmp=rsmd.getColumnName(i+1);//i+1的原因

 String ls=rs.getString(i);获得有用的能显示出来的了!     ls=(ls==null)?"":ls;

String rowClick[][]=this.getRowClick();查找出有用信息相关的链接,并非是功能选项(删除),


  for(int j=0;j<this.RowClick.size();j++) //其实就是一条一个列的href,size=1,j=0一条
                                        {
                                                int clickCol=Integer.parseInt(
                                                    rowClick[j][0]);//前面的id=1
                                                if(i==clickCol+1) i是当前列号,一开始是2,由于前面设的是1,OK,相等!!!
                                                {
                                                        if(this.ENV_TYPE==1)
                                                        {
                                                                rowClick[j][2]=
                                                                    TextTools.
                                                                    GBK2iso(
                                                                    rowClick[j][
                                                                    2]);
                                                        }
                                                        else if(this.ENV_TYPE
                                                            ==2)
                                                        {

                                                        }

                                                                                                            tmpClick="<a href=/""                                                           +rowClick[j][2]+pk
                                                            +"/""+rowClick[j][1]
                                                            +">"+ls+"</a>";

                                                        break; //找到了,构造出url及数据就break出来.

                                                }
                                        }


功能区了:
   if(this.getShowForm())
                                {
                                        listString.append(
                                            "<td><input type=/"checkbox/" name=/"deleted/" value=/""
                                            +
                                            rs.getString(this.GetCheckboxValues())   //  private int CheckboxValues=1;
                                            +"/""+Check+"></td>");   private String Check="";
                                }
其实就是    <td><input type="checkbox" name="deleted" value="1"></td>

接下来是:
 //底行按钮
                        if(this.bottomBtn.size()!=0)   // private java.util.Vector bottomBtn=new java.util.Vector();
                            {
                                listString.append(
                                    "  <tr align=/"right/" bgcolor=/""
                                    +this.getTableRowcolor1()+"/">/r/n");
                                listString.append("   <td colspan=/""
                                                  +this.columnCount+"/">");  //colspan跨度!
                                listString.append(this.getBottomClick());
                                listString.append("   </td>/r/n");
                                listString.append("  </tr>/r/n");
                        }
                       
                       
                        由于没有addBottomClick(String btnLable,String target,String arg)所以为空了!
                       
                         public boolean addBottomClick(String btnLable,String target,String arg)
        {
                String tmpString="";
                tmpString+="<a href=/"";
                tmpString+=target+arg;
                        tmpString+="/">";
                if(this.ENV_TYPE==1)
                {
                        tmpString+=btnLable;
                     
                }
                else if(this.ENV_TYPE==2)
                {
                        tmpString+=btnLable;
                }

                tmpString+="</a>"+"&nbsp;";
                this.bottomBtn.addElement(tmpString);
                return true;
        }
        这个方法增加底部功能按钮,它并不和addRowClick一样用的不是数组存!
           public String getBottomClick()
        {
                //<a href="#">dfgfdg</a>
                String tmpString="";
                String[] tmpBtn=new String[this.bottomBtn.size()];
                this.bottomBtn.toArray(tmpBtn);
                for(int i=0;i<this.bottomBtn.size();i++)
                {
                        tmpString+=tmpBtn[i];

                }
                return tmpString;
        }
//从Vector.toArray()->new String[]->String
 Go on! if(this.bottomRowFlag)  //起初是private boolean bottomRowFlag=true;可setBottomRowFlag()来设置之.先看结果:
 
  <tr align="right" bgcolor="#FFFFFF">
   <td colspan="3">   </td>
  </tr>
 
  ///
   if(this.bottomRowFlag)
                        {
                                listString.append(
                                    "  <tr hight=/"2/" bgcolor=/""
                                    +this.getTableBgcolor()+"/">/r/n"); //this.tableBgcolor="#dc6b0e";类构造时!
                                listString.append("   <td>");
                                listString.append("   </td>/r/n");
                                listString.append("  </tr>/r/n");

                                listString.append(
                                    "  <tr align=/"right/" bgcolor=/""
                                    +this.getTableLastRowBgcolor()+"/">/r/n"); this.tableLastRowBgcolor="#FFFFFF";
                                listString.append("   <td colspan=/""
                                                  +this.columnCount+"/">");
                                listString.append(this.getNav());//导航条的那个,上一页下一页什么的吧!
                                listString.append("   </td>/r/n");
                                listString.append("  </tr>/r/n");
                        }

看看最后的getNav():

 public String getNav()
        {
                String First,Previous,Next,Last,statistic,GotoPage;

                statistic=this.getStatistic();//统计!!!!
                 /**
         * 统计
         * @return boolean
         * @roseuid 3CE06C5B002E
         */
        public String getStatistic()
        {

                String sta=intl_di+this.getPageStart()+intl_yegong    //static String intl_yegong="页/共";
     //   static String intl_yegong2="页 共";
      //  static String intl_tiaojilu="条记录";
                           +this.getTotalPage()+intl_yegong2
                           +this.getTotalRecord()+intl_tiaojilu;
                if(this.ENV_TYPE==1)
                {
                        //sta = TextTools.GBK2iso(sta);
                }
                else if(this.ENV_TYPE==2)
                {

                }
                return sta;
        }

                GotoPage="<td align=/"right/" class=/"pt9/">"+intl_GotoText+
                 "<input name=/"GotoPage/" type=/"text/" size=/"2/" class=/"smbutton/"></td><td align=/"left/">"
                         +"<img src=/""+this.intl_GotoImage   //图
                         +"/" border=/"0/" οnclick=/"gotopage('"
                         +this.getOtherArg()
                         +"')/" style=/"CURSOR: hand/"></td>";
           关于gotopage的javaScript:
           function gotopage(OtherArg){
 if (OtherArg==null || OtherArg=="null")
 {
  OtherArg="";
 }
 delfrm.action="Goodslist.jsp?action=gotopage"+OtherArg;
    delfrm.submit();
 }
 this.otherArg="";在构造方法中可看到!!!
 调用时可设置之!
 不可有了URL中带参数就用的少了!可看到URL中已带参数了!
  display.init(request,firstno,20,sql,"Goodslist.jsp?condition="+condition+"&GoodsType="+GoodsType+"&KeyWord="+Key+"&")
 gotopage参数的处理在goodslist.jsp中:
 String pageno=null;
 if(request.getParameter("GotoPage")!=null && !request.getParameter("GotoPage").equals(""))
 {
  pageno=request.getParameter("GotoPage");
 }else
 {
  pageno=request.getParameter("pageStart");
 }

 if(pageno==null){pageno="1";}
 int firstno=Integer.parseInt(pageno);
 ..........................................................................................
             static String intl_di="第";
        static String intl_yegong="页/共";
        static String intl_yegong2="页 共";
        static String intl_tiaojilu="条记录";
        static String intl_GotoText="直接进入页面";
        private String intl_GotoImage="/manage/images/go.gif"; //goto图片

        static String intl_firstpage=
            "<img src=/"/manage/images/firstpage.gif/" border=/"0/">"; //首页
        static String intl_previouspage=
            "<img src=/"/manage/images/001.jpg/" border=/"0/">"; //上一页
        static String intl_nextpage=
            "<img src=/"/manage/images/002.jpg/" border=/"0/">"; //下一页
        static String intl_lastpage=
            "<img src=/"/manage/images/lastpage.gif/" border=/"0/">"; //尾页
............................................................................................

                First=(pageStart==1)?intl_firstpage+"&nbsp;"
                      :"<A HREF=/""+this.URL+"?pageStart=1&pageSize="+pageSize
                      +this.getOtherArg()+"/">"+intl_firstpage+"</A>&nbsp;";
                     
                     // 这个地方URL和pageStart及pageSize发挥作用了!
                Previous=(pageStart==1)?intl_previouspage+"&nbsp;"
                         :"<A HREF=/""+this.URL+"?pageStart="+(pageStart-1) //pageStart有用了!
                         +"&pageSize="+pageSize+this.getOtherArg()+"/">"
                         +intl_previouspage+"</A>&nbsp;";
                Next=(pageStart>=totalPage)?intl_nextpage+"&nbsp;"
                ///
                this.URL=request.getRequestURI();
                this.pageSize=((request.getParameter("pageSize")!=null)
                               ?Integer.
                               parseInt(request.getParameter("pageSize"))
                               :pageSize);
                this.pageStart=(request.getParameter("pageStart")!=null)
                               ?
                               Integer.parseInt(request.getParameter(
                                   "pageStart"))
                               :pageStart;
                               在init在获取值!
                 this.pageSize=pageSize;
                this.pageStart=pageStart;
                this.qdSQL=sql;
                               /
                     :"<A HREF=/""+this.URL+"?pageStart="+(pageStart+1)
                     +"&pageSize="+pageSize+this.getOtherArg()+"/">"
                     +intl_nextpage+"</A>&nbsp;";
                Last=(pageStart>=totalPage)?intl_lastpage+"&nbsp;"
                     :"<A HREF=/""+this.URL+"?pageStart="+totalPage+"&pageSize="
                     +pageSize+this.getOtherArg()+"/">"+intl_lastpage
                     +"</A>&nbsp;";
                String Nav="";

                if(this.totalRecord<=this.currentPageSize)
                {
                        Nav="";
                }
                else
                {
                        Nav="<table width=/"100%/"><tr align=/"center/"><td>"
                            +First+Previous+statistic+Next+Last+GotoPage
                            +"</td></tr></table>";
                }
                if(this.ENV_TYPE==1)
                {
                        Nav=Nav;
                }
                else if(this.ENV_TYPE==2)
                {

                }
                return Nav;
        }
       
最后代码是:
  if(this.getShowForm())
                        {
                                listString.append(
                                    "  <tr align=/"center/" bgcolor=/""
                                    +this.getTableLastRowBgcolor()+"/">/r/n");
                                listString.append("   <td colspan=/""
                                                  +this.columnCount+"/">");
                                listString.append(FormTitleImage); //一般是"删除",注意其name=del,其它image没name,它将会发动
                                action="../../servlet/goods.DeleteGoods" οnsubmit="return delit()"!!!
                               
                                listString.append(Reselect);
                                listString.append(SelectAll);
                                //  static String SelectAll="<img src=/"/manage/images/selectall.gif/" onClick=/"selectidall()/" style=/"CURSOR: hand/">"; //全选按纽
   //  private String FormTitleImage= "<input name=/"del/" type=/"image/" src=/"/manage/images/del.gif/" >";
      //  static String Reselect="<img src=/"/manage/images/reselect.gif/" onClick=/"formreset()/" style=/"CURSOR: hand/">"; //重选按纽
               值得注意的是Goodslist.jsp:
                    static String SelectAll="<img src=/"../images/selectall.gif/" onClick=/"selectidall()/" style=/"CURSOR: hand/">
                    <br><input name=/"show/" type=/"button/" id=/"show/" value=/"所选的商品放于首页显示/" onClick=/"javascript:showIndex();/"><input name=/"cancel/" type=/"button/" id=/"cancel/" value=/"所选商品不放于首页显示/" onClick=/"javascript:cancelIndex();/"><input name=/"showAndCancel/" type=/"hidden/" id=/"showAndCancel/" value=/"show/">"; //全选按纽
                                多加了2个button!!!
                                listString.append(
                                    "<input type=/"hidden/" name=/"v1/">");  //隐藏域!
                                listString.append("   </td>/r/n");
                                listString.append("  </tr>/r/n");
                        }
Ok!!!!!结束了!!!
收尾工作:
           rs.close();
                        stmt.close();
                }
                catch(Exception ex)
                {
                        ex.printStackTrace();
                }
                finally
                {
                        try
                        {
                                stmt.close();
                                conn.close();
                        }
                        catch(Exception ex)
                        {
                        }
                }
                if(this.ENV_TYPE==1)                      //真得是没用!!!!
                {
                        RString=listString.toString();
                }
                else if(this.ENV_TYPE==2)               //真得是没用!!!!
                {
                        RString=listString.toString();
                }

                return RString;


前台jsp调用
 String list=display.list();

<%=list%>  放在body前!

OK!88
QQ:5808112
sgwood写! 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值