编程语言

img ziying

page

发表于2004/10/16 14:04:00  722人阅读

/*
* 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

相关文章推荐

img
取 消
img