首页 > 编程 > JSP > 正文

详细的jsp分页(oracle+jsp+apache)

2024-09-05 00:20:32
字体:
来源:转载
供稿:网友

我的一个详细的jsp分页程序!(oracle+jsp+apache)

一 前提

希望最新的纪录在开头给你的表建立查询:

表:mytable

查询:create or replace view as mytable_view from mytable order by id desc 其中,最好使用序列号create sequence mytable_sequence 来自动增加你的纪录id号

二 源程序

<%string sconn="你的连接"
class.forname("oracle.jdbc.driver.oracledriver");
connection conn=drivermanager.getconnection(sconn,"你的用户名","密码");
statement stmt=conn.createstatement(resultset.type_scroll_sensitive,resultset.concur_updatable);
statement stmtcount=conn.createstatement(resultset.type_scroll_sensitive,resultset.concur_updatable);

resultset rs=stmt.executequery("select * from mytable_view");
string sqlcount="select count(*) from mytable_view";
resultset rscount=stmtcount.executequery(sqlcount);

int pagesize=你的每页显示纪录数;
int rowcount=0; //总的记录数
while (rscount
int pagecount; //总的页数
int currpage; //当前页数
string strpage;
strpage=request.getparameter("page");
if (strpage==null){
currpage=1;
}
else{
currpage=integer.parseint(strpage);
if (currpage<1) currpage=1;
}

pagecount=(rowcount+pagesize-1)/pagesize;
if (currpage>pagecount) currpage=pagecount;

int thepage=(currpage-1)*pagesize;
int n=0;
rs.absolute(thepage+1);
while (n<(pagesize)&&!rs
%>

<%rs.close();
rscount.close();
stmt.close();
stmtcount.close();
conn.close();
%>

//下面是 第几页等
<form name="sinfo" method="post" action="sbinfo_index.jsp?condition=<%=condition%>&type=<%=type%>" onsubmit="return testform(this)">
第<%=currpage%>页 共<%=pagecount%>页 共<%=rowcount%>条
<%if(currpage>1){%><a href="sbinfo_index.jsp?condition=<%=condition%>&type=<%=type%>">首页</a><%}%>
<%if(currpage>1){%><a href="sbinfo_index.jsp?page=<%=currpage-1%>&condition=<%=condition%>&type=<%=type%>">上一页</a><%}%>
<%if(currpage<pagecount){%><a href="sbinfo_index.jsp?page=<%=currpage+1%>&condition=<%=condition%>&type=<%=type%>">下一页</a><%}%>
<%if(pagecount>1){%><a href="sbinfo_index.jsp?page=<%=pagecount%>&condition=<%=condition%>&type=<%=type%>">尾页</a><%}%>
跳到<input type="text" name="page" size="4" >页
<input type="submit" name="submit" size="4" value="go" >
</form>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表