page

/*
* function page break
* param str_table :  page bread table
*       str_where :  page where the condition
*       httpfile  :  the jsp file
*       pages     :  get the request page
*/
package wap;

import java.util.*;
import java.sql.*;
import java.io.*;
import wap.DBconn;

public class page
{
ResultSet CountTopicrs=null; //init the param
ResultSet pagers=null;

private int intCountTopic=0;
public int intPageSize;
public int intPageCount;
public int intPage=0;
private String  Countsql=null,pagesql=null,str=null,str_where=null,str_order=null;
private String str_parameter="";

private String nowPage;
private String HttpFile;

DBconn conn = new DBconn();//connection the db

public void  setPages(int n)
{
 intPageSize = n;
}

public ResultSet setQuerysql(String str_table,String str_where, String httpfile,String pages,String str_order)throws SQLException
{
ResultSet r=null;
this.nowPage=pages;
this.HttpFile=httpfile;
this.str_order = str_order.trim();
/*if (inner.equals("t"))     //  inner join
{
 Countsql = "select count(*) from stationmessage a inner join localname b on a.startstation_ID = b.local_ID";//+str_table+" "+str_where;
 pagesql = "select a.*,b.* from stationmessage a inner join localname b on a.startstation_ID = b.local_ID";//+str_table+" "+str_where;
}
else{*/
   Countsql="select count(*) from "+str_table+" "+str_where;
   pagesql="select * from "+str_table+" "+str_where+" "+str_order;
//}
try{
r=querySql(Countsql,pagesql);
}catch(SQLException _ex)
{System.out.println(_ex);}
return r;
}

public ResultSet querySql(String Countsql,String pagesql)// request
throws SQLException{

if (nowPage==null)
   { intPage=1; }
else
  {
   intPage=Integer.parseInt(nowPage);
   if (intPage<1)
      intPage=1;
  }

CountTopicrs=conn.executeQuery(Countsql);  //get the count of all rs
if (CountTopicrs.next())
{
intCountTopic=CountTopicrs.getInt(1);
}

intPageCount = (intCountTopic+intPageSize-1)/intPageSize;
if (intPage>intPageCount)
{
intPage=intPageCount;
}
CountTopicrs.close();

pagers=conn.executeQuery(pagesql);
return pagers;
}

public int getCountTopic()
{
return intCountTopic;
}

public int getPageCount()
{
return intPageCount;
}

public int getIntPage()
{
return intPage;
}

public void setPfoot(String str)
{
this.str_parameter+=str;
}

public String PageFooter() {
String str = "";
int next, prev;
int temp;
prev=intPage-1;
next=intPage+1;
str +="<font style='font-size: 9pt'>总计<font color='red'>"+getCountTopic()+"</font>条记录,"+"【共<font  color='red'>"+getPageCount()+"</font>页】";
str +="【"+intPageSize+"条/页】 当前第<font color='red'>"+getIntPage()+"</font>页(列出第"+((intPageSize*getIntPage()+1)-intPageSize)+"到第"+(getIntPage()*intPageSize)+"条) &nbsp; &nbsp; ";//getIntPage()*intPageSize
if(intPage>1)
str += " <A href=" + HttpFile + "?pages=1"+str_parameter+">第一页</A> ";
else str += " 第一页 ";

if(intPage>1)
str += " <A href=" + HttpFile + "?pages=" + prev +str_parameter+ ">上一页</A> ";
else str += " 上一页 ";

if(intPage<intPageCount)
str += " <A href=" + HttpFile + "?pages=" + next +str_parameter+ ">下一页</A> ";
else str += " 下一页 ";

if(intPageCount>1&&intPage!=intPageCount)
str += " <A href=" + HttpFile + "?pages=" + intPageCount +str_parameter+ ">最后页</A>";
else str += " 最后页 </font>";
str +=" <form action="+ HttpFile +" method='post'> 转到 <INPUT TYPE='text'NAME='pages' style='border:1px solid #cccccc' size='2'>页  <input type='submit' name='Submit' value='go'></form>";
return str;
}
//close conn
public void closeConn()
{
conn.closeConn();
}

} //end.

page.jsp

 <tr><td colspan="6">信息管理</td></tr>
   <%
    String str_where="";
  //String str_where = "";
  String str_tb = "travel";
  String nowPage="";
  String str_order="order by travel_ID desc";
  nowPage=request.getParameter("pages");
     if (nowPage==null||nowPage.equals("null"))
       nowPage="0";   
       pagebreak.setPages(2);   //set page recordset
      ResultSet rs = pagebreak.setQuerysql(str_tb,str_where,"travel.jsp",nowPage,str_order);
 
  String footer = pagebreak.PageFooter();
out.print(" <tr><td>景点名称</td><td>景点地址</td><td>操作</td></tr>");
try{
    if (pagebreak.intPageCount>0)
    {
    int i=0;
    while (rs.next())
    {
    i++;

    if (i>((pagebreak.intPage-1)*pagebreak.intPageSize) &&(i<=pagebreak.intPage*pagebreak.intPageSize))
       {
        %>
         <tr><td><%=rs.getString(3)%></td><td><%=rs.getString(4)%></td><td><a href="travel.jsp?id=<%=rs.getInt(1)%>">修改</a>&nbsp;<a href="travel_del.jsp?id=<%=rs.getInt(1)%>">删除</a></td></tr>
       <%
       }
    }
    }
    rs.close();
  } catch(Exception e)
         {out.println(e.getMessage());}
    finally
         {pagebreak.closeConn();}
out.print("</table>");
out.println("<table border=0 cellspacing='0' cellpadding='0' align='center' bordercolorlight='#000000'    bordercolordark='#FFFFFF'><tr><td colspan=6  align=center>"+footer+"</td></tr>");
%>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值