jsp分页显示时点下一页还是第一页的内容

int rowcount=0;//表中的记录数
int pagesize=10;//每页多少条记录
int pagecount=0;//一共多少页面
int pagenow=1;//用户选择的页面号(第几页)
String s_count=request.getParameter("pagenow");//接收选择的链接页面
// out.println(s_count);
if(s_count!=null)
{
pagenow=Integer.parseInt(s_count);
}
// out.println(pagenow);
//***********************************
dataconn d1=new dataconn();
Connection conn=d1.getcon();
Statement stmt=conn.createStatement();
String sql="Select count(*) from system_news";
ResultSet rs=stmt.executeQuery(sql);

if (rs.next())
{
rowcount=rs.getInt(1);//记录数
//out.println(rowcount);//打印记录数
//rs.close();
}
if(rowcount%pagesize==0)
{
pagecount=rowcount/pagesize;
// out.println(pagecount);
}
else
{
pagecount=rowcount/pagesize+1;
// out.println(pagecount);
}
//desc 降序
//asc 升序
//sql="select * from login";
int sum=pagesize*(pagenow-1);

//out.println(sum);
if(sum==0)//当前页第一页时
{
sql="select top "+pagesize+" * from system_news order by id desc";
}
else{//当前页不是第一页时
sql="select top "+pagesize+" * from system_news where id not in(select top "+sum+" id from system_news order by id desc)order by id desc";
}
// sql="select * from login";
rs=stmt.executeQuery(sql);

不好意思看错了。。
你先打印下 String s_count=request.getParameter("pagenow");//接收选择的链接页面
当第二页的时候 这个值是多少追问

2

追答


rs=stmt.executeQuery(sql);这句之前
打印下sql 直接拿到数据库执行,看看得到什么结果

追问

数据库的结果是正确的,sum pagenow pagesize的变量也都打印过 没问题

追答

照你的意思是说 即使拿到最终生成的语句去数据库执行 也确实是第二页的数据
那ok,你展示部分的代码是怎样的 拿出来看看

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网