我是用JSP做的 用ACCESS 数据库 但是分页出现问题 点下一页 显示的还是第一页内容 下面显示的页面已经跳转。。谁帮我看看程序啊<%@ page import="java.sql.*" pageEncoding="utf-8"%>
<%@ page language="java" import="java.lang.Math.*" %><%@ page contentType="text/html"%>
<jsp:useBean id="conn" scope="page" class="db.db"/> <%!
ResultSet rs=null;
ResultSet rsTmp=null;
String sql="";
int PageSize=6;
int Page=1;
int totalPage=1;
String str="";
public String ShowOnePage(ResultSet rs,int Page,int PageSize){
str="";
//先将记录指针定位到相应的位置
try{
rs.absolute((Page-1)*PageSize+1);
}catch(SQLException e){
}
for(int iPage=1;iPage<=PageSize;iPage++ ){
str+=RsToGbook(rs);
try{
if(!rs.next())break;
}catch(Exception e){
System.out.println("Locate Current Page Error!");
}
}
return str;
}
//显示单行记录子模块
public String RsToGbook(ResultSet rs){
String tt="";
String email="";
String homepage="";
String name="";
String sex="";
String subject="";
String memo="";
String gtime="";
try{
email=rs.getString("email");
homepage=rs.getString("homepage");
name=rs.getString("name");
sex=rs.getString("gender");
subject=rs.getString("title");
memo=rs.getString("content");
gtime=rs.getString("gtime");
if(!email.equals("")){
email="<A href='mailto:"+email+"'><img src='images/email.gif' border='0' alt='电子邮件信箱'></A>";
}
if(homepage.equals("http://")||homepage.equals("")){
homepage="";
}else{
homepage="<A href='"+homepage+"'><img src='images/homepage.gif' border='0' alt='首页'></A>";
}
tt+="<table border='0' width='70%'>";
tt+="<tr><td><table border='0'><tr><td><img src='images/buttom-g.gif'>";
tt+=name+"</td><td>";
tt+=email+homepage;
tt+="</td><td><font style='font:9pt 宋体'>[</font><font style='font:9pt 宋体'color='bule'>"+sex;
tt+="</font><font style='font:9pt 宋体'>]</font></td></tr></table></td></tr>";
tt+="<tr><td></td></tr>";
tt+="<tr><td colspan='4'>"+"<img src='images/file.gif' border='0'alt='主题'>"+subject+"</td></tr>";
tt+="<tr><td colspan='4'>"+"<img src='images/write.gif' border='0'alt='留言'>"+memo+"</td></tr>";
tt+="<tr><td colspan='4'><font face='Arial' size='1'>["+gtime+"]</td></tr>";
tt+="<hr border='1' width='100%'></table>";
}catch(SQLException e){}
return tt;
}
%>
<%
sql="select * from gbook order by gtime desc";
try{
rs=conn.getBySql(sql);//修正
}catch(Exception e){
out.println("访问数据库出错!");
}
rsTmp=conn.getBySql("select count(*) as mycount from gbook");//修正
rsTmp.next();
int totalrecord=rsTmp.getInt("mycount");
if(totalrecord%PageSize==0)totalPage=totalrecord/PageSize;//如果是当前页的整数倍
else totalPage=(int)Math.floor(totalrecord/PageSize)+1;
if(totalPage==0)totalPage=1;
rsTmp.close();
try{
if(request.getParameter("page")==null||request.getParameter("page").equals(""))//修改page
Page=1;
else
Page=Integer.parseInt(request.getParameter("page"));// 修改。。
}catch(java.lang.NumberFormatException e){
//捕获用户从浏览器地址栏直接输入Page=sdfsdf所造成的异常
Page=1;
}
if(Page<1)Page=1;
if(Page>totalPage)Page=totalPage;
%>
<html>
<body bgcolor="#ffffff">
<div align="center">
<img src="images/gbook.gif" width="374" height="93"><br>
[<a href="form.html"><font color="red" onmouseover="this.style.color='#0000bb'" onmouseout="this.style.color='red'">我要留言</font></a>]
<%
out.println((ShowOnePage(rs,Page,PageSize)));
%>
<form action="liuyan.jsp" method="get">
<%
if(Page!=1){
out.println("<A href=liuyan.jsp?page=1>第一页</A>");
out.println("<A href=liuyan.jsp?page="+(Page-1)+">上一页</A>");
}
if(Page!=totalPage){
out.println("<A href=liuyan.jsp?page="+(Page+1)+">下一页</A>");
out.println("<A href=liuyan.jsp?page="+totalPage+">最后一页</A>");
}
rs.close();
%>
<p>输入页数:<input type="text" name="Page" size="3">页数:<font color="red"><%=Page%>/<%=totalPage%></font>
</p>
</form>
<a href="form.html">返回留言表单</a><br><br>
</div>
</body>
</html>
急着找问题啊
<%@ page language="java" import="java.lang.Math.*" %><%@ page contentType="text/html"%>
<jsp:useBean id="conn" scope="page" class="db.db"/> <%!
ResultSet rs=null;
ResultSet rsTmp=null;
String sql="";
int PageSize=6;
int Page=1;
int totalPage=1;
String str="";
public String ShowOnePage(ResultSet rs,int Page,int PageSize){
str="";
//先将记录指针定位到相应的位置
try{
rs.absolute((Page-1)*PageSize+1);
}catch(SQLException e){
}
for(int iPage=1;iPage<=PageSize;iPage++ ){
str+=RsToGbook(rs);
try{
if(!rs.next())break;
}catch(Exception e){
System.out.println("Locate Current Page Error!");
}
}
return str;
}
//显示单行记录子模块
public String RsToGbook(ResultSet rs){
String tt="";
String email="";
String homepage="";
String name="";
String sex="";
String subject="";
String memo="";
String gtime="";
try{
email=rs.getString("email");
homepage=rs.getString("homepage");
name=rs.getString("name");
sex=rs.getString("gender");
subject=rs.getString("title");
memo=rs.getString("content");
gtime=rs.getString("gtime");
if(!email.equals("")){
email="<A href='mailto:"+email+"'><img src='images/email.gif' border='0' alt='电子邮件信箱'></A>";
}
if(homepage.equals("http://")||homepage.equals("")){
homepage="";
}else{
homepage="<A href='"+homepage+"'><img src='images/homepage.gif' border='0' alt='首页'></A>";
}
tt+="<table border='0' width='70%'>";
tt+="<tr><td><table border='0'><tr><td><img src='images/buttom-g.gif'>";
tt+=name+"</td><td>";
tt+=email+homepage;
tt+="</td><td><font style='font:9pt 宋体'>[</font><font style='font:9pt 宋体'color='bule'>"+sex;
tt+="</font><font style='font:9pt 宋体'>]</font></td></tr></table></td></tr>";
tt+="<tr><td></td></tr>";
tt+="<tr><td colspan='4'>"+"<img src='images/file.gif' border='0'alt='主题'>"+subject+"</td></tr>";
tt+="<tr><td colspan='4'>"+"<img src='images/write.gif' border='0'alt='留言'>"+memo+"</td></tr>";
tt+="<tr><td colspan='4'><font face='Arial' size='1'>["+gtime+"]</td></tr>";
tt+="<hr border='1' width='100%'></table>";
}catch(SQLException e){}
return tt;
}
%>
<%
sql="select * from gbook order by gtime desc";
try{
rs=conn.getBySql(sql);//修正
}catch(Exception e){
out.println("访问数据库出错!");
}
rsTmp=conn.getBySql("select count(*) as mycount from gbook");//修正
rsTmp.next();
int totalrecord=rsTmp.getInt("mycount");
if(totalrecord%PageSize==0)totalPage=totalrecord/PageSize;//如果是当前页的整数倍
else totalPage=(int)Math.floor(totalrecord/PageSize)+1;
if(totalPage==0)totalPage=1;
rsTmp.close();
try{
if(request.getParameter("page")==null||request.getParameter("page").equals(""))//修改page
Page=1;
else
Page=Integer.parseInt(request.getParameter("page"));// 修改。。
}catch(java.lang.NumberFormatException e){
//捕获用户从浏览器地址栏直接输入Page=sdfsdf所造成的异常
Page=1;
}
if(Page<1)Page=1;
if(Page>totalPage)Page=totalPage;
%>
<html>
<body bgcolor="#ffffff">
<div align="center">
<img src="images/gbook.gif" width="374" height="93"><br>
[<a href="form.html"><font color="red" onmouseover="this.style.color='#0000bb'" onmouseout="this.style.color='red'">我要留言</font></a>]
<%
out.println((ShowOnePage(rs,Page,PageSize)));
%>
<form action="liuyan.jsp" method="get">
<%
if(Page!=1){
out.println("<A href=liuyan.jsp?page=1>第一页</A>");
out.println("<A href=liuyan.jsp?page="+(Page-1)+">上一页</A>");
}
if(Page!=totalPage){
out.println("<A href=liuyan.jsp?page="+(Page+1)+">下一页</A>");
out.println("<A href=liuyan.jsp?page="+totalPage+">最后一页</A>");
}
rs.close();
%>
<p>输入页数:<input type="text" name="Page" size="3">页数:<font color="red"><%=Page%>/<%=totalPage%></font>
</p>
</form>
<a href="form.html">返回留言表单</a><br><br>
</div>
</body>
</html>
急着找问题啊
解决方案 »
- ISA服务器转发请求,IP获取问题
- 100分请高手回答一下:JSP中的缓冲区buffer到底应该多少算好呢?还有个问题是如何建立索引
- 请问server.xml里设置了虚拟目录之后为什么无法访问?
- 使地址栏内容不变的问题:我用jsp做的网站,首页为html的!
- 大侠,大侠,救救我啊!急!
- 关于javabean的电子图书?
- JDBC中打开一个连接Connection而不关闭会有什么后果?
- 一个输出主体的标记库,死也调试不出结果。。。
- 复选框选中某一行后,这行有文本框,怎么取到值提交form表单?
- 一个java项目有代码,怎么可以让它运行起来
- ibatis动态字段不显示?
- 发生这个意外...java.lang.NullPointerException ,这是什么意思啊
try{
rs.absolute((Page-1)*PageSize+1);
}catch(SQLException e){
}
for(int iPage=1;iPage <=PageSize;iPage++ ){
str+=RsToGbook(rs);
try{
if(!rs.next())break;
}catch(Exception e){
System.out.println("Locate Current Page Error!");
}
}
return str;
}
问题在上边吧
在翻页的时候要对Page重新赋值。
没仔细看,好像没有赋值的地方