网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 jsp分页显示完整实例
内容
    这篇文章主要介绍了jsp分页显示完整实例,以文章管理页面为例详细分析了jsp的分页显示实现技巧,具有一定参考借鉴价值,需要的朋友可以参考下
    本文实例讲述了jsp分页显示的实现方法。分享给大家供大家参考。
    具体实现方法如下:
    代码如下:
    <%@ page contenttype=text/html; charset=gb2312 language=java import=java.sql.* errorpage= %>
    < file =../inc/chkpwd.jsp%>
    < file=../db.jsp%>
    <!doctype html public -//w3c//dtd xhtml 1.0 transitional//en >
    <html xmlns=>
    <head>
    <meta name=robots content=noindex,nofollow />
    <meta http-equiv=content-type content=text/html; charset=gb2312 />
    <title>文章管理</title>
    <link href=style.css rel=stylesheet type=text/css />
    </head>
    <body>
    <table width=98% height=77% border=0 cellpadding=0 cellspacing=0>
    <tr class=style1>
    <td width=100% height=26 background=images/admin_bg_1.gif><strong><font color=#ffffff>--<span class=style1>内容管理</span></font></strong></td>
    </tr>
    <tr>
    <td colspan=10>
    </td>
    </tr>
    <tr class=title>
    <td height=25 background=images/admin_bg_1.gif class=t2>|
    <%
    string op;
    string id = request.getparameter(id);
    op = request.getparameter(op);
    if(op==null){
    op = my;
    }
    if (op.equals(del) && id!=null){
    string bbb = new string(request.getparameter(bigclassname).getbytes(iso8859_1));
    statement stmt_channeldel=conn.createstatement();
    string sqldel=delete from hl_news where id= + id;
    int shan=stmt_channeldel.executeupdate(sqldel);
    if (shan>0)
    {
    out.print(<script type=text/javascript> alert(已成功删除!); window.location.href='hanye_manages.jsp?bigclassname=+bbb+'; </script>);
    }
    stmt_channeldel.close();
    return ;
    }
    statement stmta=conn.createstatement(resultset.type_scroll_sensitive,resultset.concur_read_only);
    string sqla=select * from hl_smallclass where bigname='行业新闻' order by id asc;
    resultset rsa=stmta.executequery(sqla);
    while (rsa.next()) {
    %>
    <a class='t2' href='hanye_manages.jsp?modi=新闻&bigclassname=<%=rsa.getstring(smallname)%>'><%=rsa.getstring(smallname)%></a> |
    <%
    }
    rsa.close(); //关闭记录集对象
    stmta.close(); //关闭语句对象
    %>
    </td>
    </tr>
    <tr>
    <td height=20></td>
    </tr>
    <tr>
    <td valign=top bgcolor=#ecf5ff>
    <form name=form2 action=list.asp?action=delall&modi=新闻 method=post>
    <table width=100% cellpadding=3 cellspacing=2 bgcolor=#ffffff style=word-break:break-all>
    <tr class=t2>
    <td width=32 height=28 background=images/admin_bg_1.gif bgcolor=#bbdaff class=style1 >id</td>
    <td width=80 background=images/admin_bg_1.gif bgcolor=#bbdaff class=style1 >新闻大类</td>
    <td width=88 background=images/admin_bg_1.gif bgcolor=#bbdaff class=style1 >新闻小类</td>
    <td width=291 background=images/admin_bg_1.gif bgcolor=#bbdaff class=style1 style=word-break:break-all >新闻标题</td>
    <td width=179 background=images/admin_bg_1.gif bgcolor=#bbdaff class=style1 >新闻图片</td>
    <td width=76 background=images/admin_bg_1.gif bgcolor=#bbdaff class=style1 >发布时间</td>
    <td width=64 background=images/admin_bg_1.gif bgcolor=#bbdaff class=style1>操作</td>
    </tr>
    <%
    int pagesize=10; //每页显示的文章数
    int showpage=1; //当前页面显示的页号
    int reccount=0; //resultset中的文章总数
    int pagecount=0; //分页后的总页数
    string sqlarticle;
    string topage = request.getparameter(page);
    string bgname = new string(request.getparameter(bigclassname).getbytes(iso8859_1));
    statement stmt_article=conn.createstatement(resultset.type_scroll_sensitive,resultset.concur_read_only);
    sqlarticle=select * from hl_news where smallname='+bgname+' order by id desc;
    resultset rsarticle=stmt_article.executequery(sqlarticle);
    if(rsarticle.next()) {
    rsarticle.last();//指针飞到最后
    reccount=rsarticle.getrow();//去除最后一行的行号
    pagecount=((reccount%pagesize)==0?(reccount/pagesize):(reccount/pagesize)+1);//得到一共可以分多少页
    if(topage!=null)
    showpage=integer.parseint(topage);
    rsarticle.absolute((showpage-1)*pagesize+1);//跳到第showpage页的第一条
    for(int i=1;i<=pagesize;i++){
    int nid=rsarticle.getint(id);
    string img = rsarticle.getstring(img);
    string ttt = rsarticle.getstring(times);
    //ttt=ttt.substring(0,10);
    %>
    <tr class=style1>
    <td width=32 height=22 bgcolor=#bbdaff><%=nid%></td>
    <td bgcolor=#bbdaff ><%=rsarticle.getstring(bigname)%></td>
    <td bgcolor=#bbdaff ><%=rsarticle.getstring(smallname)%></td>
    <td align=left bgcolor=#bbdaff ><%=rsarticle.getstring(title)%></td>
    <td bgcolor=#bbdaff ><a href=/<%=img%> target=_blank><%=img%></a></td>
    <td bgcolor=#bbdaff ><%=ttt%></td>
    <td width=64 bgcolor=#bbdaff class=style1><a href=hanye_edit.jsp?id=<%=nid%>&modi=新闻>修改</a>|<a href=hanye_manages.jsp?id=<%=nid%>&op=del&bigclassname=<%=bgname%> onclick=return confirm('删除后将不能恢复,你确定删除么?')>删除</a></td>
    </tr>
    <%
    if(!rsarticle.next())
    break;
    }
    }
    %>
    <input name='allid' type='hidden' value=>
    </table>
    <table width=100% border=0 cellpadding=0 cellspacing=0>
    <tr class=style1>
    <td width=50% align=left background=images/admin_bg_1.gif>
    <span class=t2><strong></strong>
    </span>
    <label>
    </label>
    </td>
    <td width=56% background=images/admin_bg_1.gif>
    <div align=left class=t2>
    共<%=pagecount%>页 <% for(int i=1;i<=pagecount;i++){ %> <% if(i==showpage){ %><b><%=i %></b><% }else{ %>[<a href='hanye_manages.jsp?bigclassname=<%=bgname%>&page=<%=i %>&modi=新闻'><%=i %></a>] <% } } %>
    </div></td>
    </tr>
    </table>
    </form>
    <form name=form1 method=post action=hanye_manage.jsp> <table width=51% border=0 cellspacing=0 cellpadding=0>
    <tr class=t4>
    <td width=34% height=23><span class=style1>查询:</span>
    <label>
    <select name=select>
    <option value=id>按id查询</option>
    <option value=title>按标题查询</option>
    <option value=times>按时间查询</option>
    </select>
    </label>
    <label>
    <input type=text name=k>
    <input name=submit type=submit class=t5 value=提交>
    </label> </td>
    </tr>
    </table>
    </form>
    <br></td>
    </tr>
    </table>
    <%
    rsarticle.close();
    stmt_article.close();
    conn.close();
    %>
    </body>
    </html>
    希望本文所述对大家的jsp程序设计有所帮助。
随便看

 

在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/16 17:42:21