用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - jsp代码库

jsp分页代码 原始版

2012-09-25 作者: 神马举报

[jsp]代码库

<%@ page contentType="text/html;charset=gb2312"%>
<%@ page language="java" import="java.sql.*"%>
 
 
<script language="javascript">
function newwin(url) {
var newwin=window.open(url,"newwin","toolbar=no,location=no,directories=no,status=no,menubar=no, scrollbars=yes,resizable=yes,width=600,height=450");
newwin.focus();
return false;
}
</script>
 
<script language="javascript">
function submit10()
{
self.location.replace("index.jsp")
}
</script>
 
<%
    //jsp分页代码原始版
 
    java.sql.Connection sqlCon;
    java.sql.Statement sqlStmt;
    java.sql.ResultSet sqlRst;
    java.lang.String strCon;
    java.lang.String strSQL; //SQL语句
    int intPageSize; //一页显示的记录数
    int intRowCount; //记录总数
    int intPageCount; //总页数
    int intPage; //待显示页码
    java.lang.String strPage;
    int i;
    //设置一页显示的记录数
    intPageSize = 4;
    //取得待显示页码
    strPage = request.getParameter("page");
    if (strPage == null) {//表明在QueryString中没有page这一个参数,此时显示第一页数据
        intPage = 1;
    } else {//将字符串转换成整型
        intPage = java.lang.Integer.parseInt(strPage);
        if (intPage < 1)
            intPage = 1;
    }
 
    //连接数据库
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    strCon = "jdbc:odbc:heyang";
    sqlCon = java.sql.DriverManager.getConnection(strCon, "sa", "");
 
    //创建一个可以滚动的只读的SQL语句对象
    sqlStmt = sqlCon.createStatement(
            java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
            java.sql.ResultSet.CONCUR_READ_ONLY);//准备SQL语句
 
    //执行SQL语句并获取结果集
    strSQL = "select user_id,user_name from userinfo order by user_id desc";
    sqlRst = sqlStmt.executeQuery(strSQL);
 
    sqlRst.last();//光标在最后一行
    intRowCount = sqlRst.getRow();//获得当前行号
 
    intPageCount = (intRowCount + intPageSize - 1) / intPageSize;//记算总页数
    //调整待显示的页码
    if (intPage > intPageCount)
        intPage = intPageCount;
%>
 
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
        <title>会员管理</title>
    </head>
    <body>
        <form method="POST" action="index.jsp">
            第<%=intPage%>页 共<%=intPageCount%>页
 
            <%
            if (intPage < intPageCount) {
        %>
 
            <a href="index.jsp?page=<%=intPage + 1%>">下一页 </a>
 
            <%
                }
            %>
 
            <%
                if (intPage > 1) {
            %>
 
            <a href="index.jsp?page=<%=intPage - 1%>"> 上一页</a>
 
            <%
                }
            %>
 
            转到第:
            <input type="text" name="page" size="8">
            
            <span><input class=buttonface type=&acute;submit&acute;
                    value=&acute;GO&acute; name=&acute;cndok&acute;> </span>
        </form>
        <table border="1" cellspacing="0" cellpadding="0">
            <tr>
                <th>
                    ID
                </th>
                <th>
                    用户名
                </th>
                <th width=&acute;8%&acute;>
                    删除
                </th>
            </tr>
            <%
                if (intPageCount > 0) {
                    //将记录指针定位到待显示页的第一条记录上
                    sqlRst.absolute((intPage - 1) * intPageSize + 1);
                    //显示数据
                    i = 0;
                    String user_id, user_name;
                    while (i < intPageSize && !sqlRst.isAfterLast()) {
                        user_id = sqlRst.getString(1);
                        user_name = sqlRst.getString(2);
            %>
            <tr>
                <td><%=user_id%></td>
                <td><%=user_name%></td>
                <td width=&acute;8%&acute; align=&acute;center&acute;>
                    <a href="delete.jsp?user_id=<%=user_id%>"
                        onClick="return newwin(this.href);">删除</a>
                </td>
            </tr>
            <%
                sqlRst.next();
                        i++;
                    }
                }
            %>
        </table>
 
 
    </body>
</html>
 
<%
    //关闭结果集
    sqlRst.close();
    //关闭SQL语句对象
    sqlStmt.close();
    //关闭数据库
    sqlCon.close();
%>


网友评论    (发表评论)

共1 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...