to 回复人:AWUSOFT外事不决问google________________________________什么意思啊?外事不决问google 内事不决问老婆 哈
public String getPage(){ if(log.isDebugEnabled()) { log.debug("�����Z��,��nc.sb29.page.Page.class����getPage()"); } Connection conn = null; PreparedStatement pstmt = null; ResultSet total = null; StringBuffer sql = new StringBuffer(50); try { if(term.equals("")){ sql.append("select count(*) as A from ") .append(table); }else{ sql.append("select count(*) as A from ") .append(table) .append(" where ") .append(term); } conn = DBMssql.getConnection(); pstmt = conn.prepareStatement(sql.toString()); total = pstmt.executeQuery(); if(total.next()){ totaldate = total.getInt("A"); } totalpage = (totaldate+ipage-1)/ipage;
if(totalpage>=0){ if(currentlypage>totalpage){ currentlypage = totalpage; } } if(currentlypage<1){ currentlypage = 0; } sql.delete(0, sql.length()); if (term.equals("")) { sql.append("select top ") .append(ipage) .append(" * from ") .append(table) .append(" where id not in (select top ") .append(ipage*(currentlypage-1)) .append(" id from ") .append(table) .append(" order by ") .append(with) .append(desc) .append(") order by ") .append(with) .append(desc); }else{ sql.append("select top ") .append(ipage) .append(" * from ") .append(table) .append(" where id not in (select top ") .append(ipage*(currentlypage-1)) .append(" id from ") .append(table) .append(" where ") .append(term) .append(" order by ") .append(with) .append(desc) .append(") and ") .append(term) .append(" order by ") .append(with) .append(desc); } } catch(SQLException e) { log.error("Error occurs when do method String getPage() in nc.sb29.page.Page.class:\n"+e.toString()); }finally{ DBMssql.closeResultSet(total); DBMssql.closePreparedStatement(pstmt); DBMssql.closeConnection(conn); } return sql.toString(); }
import java.sql.*; int page;//当前页 int maxpage//一共有多少页 int pagerow;每页有多少行 int maxrow;总共有多少行public Connection bdcon(){ Connection con=null; try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con=DriverManager.getConnection("jdbc:odbc:test"); }catch(Exception ce){ System.out.println (ce.toString()); } return con; } public void select(){ try{ int i=0; Connection con=bdcon(); Statement rs=con.createStatement(); ResultSet s=rs.executeQuery("select * from table"); while(s.next()){ i++; } maxrow=i if(maxrow%page==0){ maxpage=maxrow/page; }else{ maxpage=maxrow/page+1; } }catch(Exceptio ce){ System.out.println(ce.toString()); } } 提示:要把上面的代码写在构造方法里面呀一定呀!!!! 只要一运行就加载到当前的页面呀!!! 这样就把总页和总行和就做出来了呀!!! 未完...
网上很多分布的例子,自己去找一下吧.
推荐用标签吧 display不错的 外观挺好 功能也比较强大
<!-- 定义的几个常量 -->
<%! private static final int SIZE = 15;//页面大小%>
<%! private static final int LIMIT = 10;//每次只显示8个页面连接 %>
<%! private static final Searcher infoSearch = new Searcher();%><!-- 得到 分页需要用到的变量 -->
<%
List list = null;//结果集
long total = 0;//记录总数
int pageCount = 1;//总页数
String keyword = request.getParameter("keyword");//搜索关键字
String category = request.getParameter("category");//搜索类型
String pp = request.getParameter("p");//第几个页面临时值
if(pp == null || !pp.matches("\\d+")) {
pp = "1";
}
int p = 1;
p = Integer.parseInt(pp);//当前页
if (keyword != null && keyword != "") {
total = infoSearch.total(keyword, category);
pageCount = (int) (total / SIZE);
if(total % SIZE != 0) {
pageCount += 1;
}
if(p > pageCount) {
p = pageCount;
}
SearchResults results = infoSearch.search(keyword, category, (p-1), SIZE);
if(results != null) {
list = results.getResultList();
}
}
%><!-- 分页具体代码 -->
<div id=page1>
<div id=pageLeft>共 <%=total%> 张壁纸 共 <%=pageCount%> 页</div>
<%
if(pageCount <= 1) {
%>
<div id=pageCenter>[上一页] [下一页]</div>
<%
} else if(pageCount > 1) {
%>
<div id=pageCenter><%if(p <= 1) {%>[上一页]<%} else {%>
[<a href="result.jsp?keyword=<%=URLEncoder.encode(keyword, "GBK")%>&category=<%=category%>&p=<%=p - 1%>">上一页</a>]<%}%>
<%
int k = (p - 1) / LIMIT;
for(int i = k * LIMIT + 1; i <= (k + 1) * LIMIT && i <= pageCount; i++) {
if(i == p) {
%>
[<%=i%>]
<%
} else {
%>
[<a href="result.jsp?keyword=<%=URLEncoder.encode(keyword, "GBK")%>&category=<%=category%>&p=<%=i%>"><%=i%></a>]
<%
}
}
%>
<%if(p >= pageCount) {%>[下一页]<%} else {%>[<a href="result.jsp?keyword=<%=URLEncoder.encode(keyword, "GBK")%>&category=<%=category%>&p=<%=p + 1%>">下一页</a>]<%}%></div>
<%
}
%>
内事不决问老婆
哈
if(log.isDebugEnabled()) {
log.debug("�����Z��,��nc.sb29.page.Page.class����getPage()");
}
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet total = null;
StringBuffer sql = new StringBuffer(50);
try {
if(term.equals("")){
sql.append("select count(*) as A from ")
.append(table);
}else{
sql.append("select count(*) as A from ")
.append(table)
.append(" where ")
.append(term);
}
conn = DBMssql.getConnection();
pstmt = conn.prepareStatement(sql.toString());
total = pstmt.executeQuery();
if(total.next()){
totaldate = total.getInt("A");
}
totalpage = (totaldate+ipage-1)/ipage;
if(totalpage>=0){
if(currentlypage>totalpage){
currentlypage = totalpage;
}
}
if(currentlypage<1){
currentlypage = 0;
}
sql.delete(0, sql.length());
if (term.equals("")) {
sql.append("select top ")
.append(ipage)
.append(" * from ")
.append(table)
.append(" where id not in (select top ")
.append(ipage*(currentlypage-1))
.append(" id from ")
.append(table)
.append(" order by ")
.append(with)
.append(desc)
.append(") order by ")
.append(with)
.append(desc);
}else{
sql.append("select top ")
.append(ipage)
.append(" * from ")
.append(table)
.append(" where id not in (select top ")
.append(ipage*(currentlypage-1))
.append(" id from ")
.append(table)
.append(" where ")
.append(term)
.append(" order by ")
.append(with)
.append(desc)
.append(") and ")
.append(term)
.append(" order by ")
.append(with)
.append(desc);
}
} catch(SQLException e) {
log.error("Error occurs when do method String getPage() in nc.sb29.page.Page.class:\n"+e.toString());
}finally{
DBMssql.closeResultSet(total);
DBMssql.closePreparedStatement(pstmt);
DBMssql.closeConnection(conn);
}
return sql.toString();
}
int page;//当前页
int maxpage//一共有多少页
int pagerow;每页有多少行
int maxrow;总共有多少行public Connection bdcon(){
Connection con=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:test");
}catch(Exception ce){
System.out.println (ce.toString());
}
return con;
}
public void select(){
try{
int i=0;
Connection con=bdcon();
Statement rs=con.createStatement();
ResultSet s=rs.executeQuery("select * from table");
while(s.next()){
i++;
}
maxrow=i
if(maxrow%page==0){
maxpage=maxrow/page;
}else{
maxpage=maxrow/page+1;
}
}catch(Exceptio ce){
System.out.println(ce.toString());
}
}
提示:要把上面的代码写在构造方法里面呀一定呀!!!!
只要一运行就加载到当前的页面呀!!!
这样就把总页和总行和就做出来了呀!!!
未完...
<HEAD>
<%@ page
language="java"
contentType="text/html; charset=GBK"
import="java.sql.*,com.linkdb.*"%>
<META http-equiv="Content-Type" content="text/html; charset=GBK">
<META name="GENERATOR" content="IBM WebSphere Studio">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK rel="stylesheet" type="text/css">
<link href="../font.css" rel="stylesheet" type="text/css">
<TITLE></TITLE>
<style type="text/css">
<!--
a:link { color: #000000; text-decoration: none}
a:visited { color: #000000; text-decoration: none}
a:hover { color: #800080; text-decoration: none}
a:active { color: #800080; text-decoration: none}
-->
</style>
</HEAD>
<jsp:useBean id="qx" class="com.dbopt.Ryxxoptbean" scope="page"></jsp:useBean>
<%
request.setCharacterEncoding("GBK");
response.setContentType("text/html;charset=GBK");
String bmbm2=(String)session.getAttribute("Bmbm");
// System.out.println(bmbm2);
//String bmbm2=(String)application.getAttribute("Bmbm");
String rybh2=(String)session.getAttribute("Rybh");
// String rybh2=(String)application.getAttribute("Rybh");
String fl=request.getParameter("fl");
String lmid=request.getParameter("cdid");
%><BODY topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">
<br>
<form method="post" name="frm" action="../Wjdelsvlt?wjid=<%=lmid%>&fl=<%=fl%>">
<a href="javascript:document.frm.submit();"><img border="0" src="../images/del1.JPG" width="38" height="22"></a>
<A href="../xxsjy/dataly.jsp?rybh=<%=rybh2%>&cdid=<%=lmid%>&bmbm=<%=bmbm2%>&fl=<%=fl%>"
target="_self"><font size="2">
<img border="0" src="../images/new1.JPG" width="38" height="20"></font></A>
<CENTER>
<TABLE border="1">
<TBODY>
<TR>
<TD width="30" align="center">   </TD>
<TD width="400" class="style9" align="center">标题</TD>
<TD width="100" class="style9" align="center">创建日期</TD> </TR>
<%
int Lmid=Integer.parseInt(lmid);
//System.out.println(Lmid);
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String strSQL = "";
int PageSize = 10;
int Page = 1;
int totalPage = 1;
int totalrecord = 0; AbstractPersistenceFactory con=new AbstractPersistenceFactory();
//Conndata con=new Conndata();
try{
conn=con.getconnections();
stmt=conn.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
if(rybh2.equals("ry001")){
strSQL = "SELECT count(*) as recordcount FROM t_wjxxb where sslmid="+Lmid;
}else{
strSQL = "SELECT count(*) as recordcount FROM t_wjxxb where sslmid="+Lmid+"and cjrmc='"+rybh2+"'";
}
//strSQL = "SELECT count(*) as recordcount FROM t_wjxxb where sslmid="+Lmid+"and cjrmc='"+rybh2+"'";
rs = stmt.executeQuery(strSQL);
if (rs.next()) totalrecord = rs.getInt("recordcount");
if(rybh2.equals("ry001")){
strSQL = "SELECT * FROM t_wjxxb where sslmid="+Lmid+" order by cjrq desc";
}else{
strSQL = "SELECT * FROM t_wjxxb where sslmid="+Lmid+"and cjrmc='"+rybh2+"' order by cjrq desc";
}
rs = stmt.executeQuery(strSQL);
if(totalrecord % PageSize ==0)
totalPage = totalrecord / PageSize;
else
totalPage = (int) Math.floor( totalrecord / PageSize ) + 1;
if(totalPage == 0) totalPage = 1;
if(request.getParameter("Page")==null || request.getParameter("Page").equals(""))
Page = 1;
else
try {
Page = Integer.parseInt(request.getParameter("Page"));
}
catch(java.lang.NumberFormatException e){
Page = 1;
}
if(Page < 1) Page = 1;
if(Page > totalPage) Page = totalPage;
rs.absolute((Page-1) * PageSize + 1);
//out.print("<TABLE BORDER='1'>");
for(int iPage=1; iPage<=PageSize; iPage++)
{
out.print("<TR><TD width='30' align='center'><P><INPUT type='checkbox' name='xuanze' value="+rs.getInt("wjid")+"></P></TD></TD>");
out.print("<TD width='400' class='style9'><A target='_self' href='../xxsjy/yulan.jsp?id="+rs.getInt("wjid")+"&fl="+fl+"&cdid="+lmid+"'>"+rs.getString("bt")+"</A></TD>");
String aaa=rs.getString("cjrq").toString();
aaa=aaa.substring(0,aaa.length()-10);
out.print("<TD width='100' align='center' class='style9'>"+aaa+"</TD>");
if(!rs.next()) break;
}
//out.print("</TABLE>");
}
catch(SQLException e){
System.out.println(e.getMessage());
}
finally
{
if(rs!=null)
{
rs.close();
rs=null;
}
if(stmt!=null)
{
stmt.close();
stmt=null;
}
if(conn!=null)
{
conn.close();
conn=null;
}
}
%>
</TABLE>
</CENTER>
</form><table width="542" border="0" cellspacing="0" cellpadding="0">
<tr><td height="23" class='style7' align="center">
<FORM Action="lmxx.jsp?cdid=<%=lmid%>" Method="post"><% if(Page != 1) {
out.print(" <A class='style7' HREF=lmxx.jsp?cdid="+Lmid+"&fl="+fl+"&Page=1>第一页</A>");
out.print(" <A class='style7' HREF=lmxx.jsp?cdid="+Lmid+"&fl="+fl+"&Page=" + (Page-1) + ">上一页</A>");
}
if(Page != totalPage) {
out.print(" <A class='style7' HREF=lmxx.jsp?cdid="+Lmid+"&fl="+fl+"&Page=" + (Page+1) + ">下一页</A>");
out.print(" <A class='style7' HREF=lmxx.jsp?cdid="+Lmid+"&fl="+fl+"&Page=" + totalPage + ">最后页</A>");
}
%> <font COLOR="red" > 输入页数:<input TYPE="TEXT" Name="Page" SIZE="2"> 页数:<%=Page%>/<%=totalPage%></font>
</FORM>
</td></tr></table>
</BODY>
</HTML>