一个分页的类及调用的例子

一个有决心的人,将会找到他的道路。淡定是一种真,更是一种善;淡定是一种美,更是一种崇高。有些事情,不谈是个结,谈开了是个疤。爱自己,取悦自己,让自己从内到外的淡定从容智慧饱满。
//PageCt.java分页的类/****@version**************Createdon2001年6月25日,下午14:41***************************************/packagevod;importjava.sql.*;importjava.util.*;publicclassPageCt{privatelongl_start;//开始纪录privatelongl_end;//结束纪录privatelongl_curpage;//当前页数privatelongl_totalnum;//总记录数privateintint_num=5;//每页10条privatelongl_totalpage;//总的页数publicvoidInit(longcurrentpage,longtotalnum){l_curpage=currentpage;l_totalnum=totalnum;if(currentpage>=0){if(currentpage>=(long)Math.ceil((double)l_totalnum/(double)int_num))l_curpage=(long)Math.floor((double)l_totalnum/(double)int_num);elsel_curpage=currentpage;}else{l_curpage=0;}l_start=l_curpage*int_num;l_end=l_start+int_num;if(l_end>l_totalnum)l_end=l_totalnum;l_totalpage=(long)Math.ceil((double)l_totalnum/(double)int_num);}publiclonggetCurpage(){returnl_curpage;}publiclonggetPrepage(){if(l_curpage-1>=0){returnl_curpage-1;}else{return0;}}publiclonggetNextpage(){if(l_curpage+1<=l_totalpage){returnl_curpage+1;}else{returnl_totalpage;}}publiclonggetTotalnum(){returnl_totalnum;}publiclonggetTotalpage(){returnl_totalpage;}publiclonggetStart(){returnl_start;}publiclonggetEnd(){returnl_end;}};===============================================//调用例子<%/****@author马毅**************@version**************Createdon2001年6月12日,下午17:13***************************************/<%@pageimport="java.sql.*"%><%@pageimport="java.lang.*"%><%@pagecontentType="text/html;charset=gb2312"%><jsp:useBeanid="PageCount"scope="page"class="kstest.PageCt"/><jsp:useBeanid="sqlbean"scope="page"class="vod.sql_data"/><html><head><TITLE>测试</TITLE><STYLE>body,table{font-size:9pt}A:link{COLOR:#000084;TEXT-DECORATION:none}A:visited{COLOR:#000084;TEXT-DECORATION:none}A:hover{COLOR:black;TEXT-DECORATION:underline}.ourfont{FONT-SIZE:9pt}</STYLE></head><bodybgcolor=#eff3ff><center><fontcolor=#000084><h3>TestforTest</h3></font><hrwidth=600color=#b5dbff><br><%ResultSetrs0=sqlbean.executeQuery("selectcount(*)fromUserList);rs0.next();longdata_num=rs0.getLong(1);longCurrent_Page=0;Stringcurrentpage=(String)request.getParameter("currentpage");if(currentpage!=null&&!currentpage.equals("")){Current_Page=Integer.parseInt(request.getParameter("currentpage"));}StringQuery_Page=(String)request.getParameter("Query_Page");if(Query_Page!=null&&!Query_Page.equals("")){Current_Page=Integer.parseInt(request.getParameter("Query_Page"))-1;}PageCt.Init(Current_Page,data_num);longl_start=PageCt.getStart();longl_end=PageCt.getEnd();//查询记录ResultSetrs=sqlbean.executeQuery("select*fromUserList");longi=0;while((i<l_start)&&rs.next()){i++;}//输出查询结果longj=0;while(rs.next()&&(i<l_end)){j=i+1;Stringcol2=rs.getString(2);Stringcol3=rs.getString(3);Stringcol4=rs.getString(4);Stringcol5=rs.getString(5);Stringcol6=rs.getString(6);Stringcol7=rs.getString(7);Stringcol8=rs.getString(8);//打印所显示的数据out.println("<tableborder=0width=600>");out.println("<tr><tdcolspan=2><fontcolor=#000084>"+j+"、"+(col2==null?"":col2)+"</font></td></tr><tr><tdcolspan=2>答案:"+(col3==null?"":col3)+"</td></tr>");out.println("<tr><td>选项1:"+(col4==null?"":col4)+"</td><td>选项2:"+(col5==null?"":col5)+"</td></tr>");out.println("<tr><td>选项3:"+(col6==null?"":col6)+"</td><td>选项4:"+(col7==null?"":col7)+"</td></tr>");if(col8!=null&&!col8.equals("")){out.println("<tr><tdcolspan=2>备注:"+col8+"</td></tr>");}out.println("</table><br>");i++;}%><tablewidth=600><trbgcolor=#b5dbff><formmethod=GETaction=index.jsp><tdwidth=80align=centervalign=bottom>共<%=PageCt.getTotalnum()%>条</td><tdwidth=80align=centervalign=bottom><%=PageCt.getCurpage()+1%>/<%=PageCt.getTotalpage()%>页</td><tdwidth=120align=center>查看第<inputtype=textname=Query_Pagesize=3>页</td><tdwidth=50align=centervalign=bottom><arel="nofollow noopener noreferrer" href=index.jsp?currentpage=<%=PageCt.getPrepage()%>>上页</a></td><tdwidth=50align=centervalign=bottom><arel="nofollow noopener noreferrer" href=index.jsp?currentpage=<%=PageCt.getNextpage()%>>下页</a></td></tr></table><br><br><br><tablecellspacing=20><tr><td>问题包含<inputtype=textname=question_strsize=10value=<%if(question_str!=null)out.println(question_str);%>></td><td>答案包含<inputtype=textname=answer_strsize=10value=<%if(answer_str!=null)out.println(answer_str);%>></td><td>选项包含<inputtype=textname=sel_strsize=10value=<%if(sel!=null)out.println(sel);%>></td></tr><tr><tdcolspan=3align=center><inputtype=submitvalue=查询></td></tr></form></table><br><br><arel="nofollow noopener noreferrer" href="insert.jsp">添加</a><center></body></html>

以上就是一个分页的类及调用的例子。人无我有,人有我优,人优我奇。更多关于一个分页的类及调用的例子请关注haodaima.com其它相关文章!