Jsp+Model

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

        Connection ct = DriverManager
                .getConnection(
                        "jdbc:sqlserver://127.0.0.1:1433;databaseName=spdb1",
                        "sa", "123456");

        Statement sm = ct.createStatement();
        ResultSet rs = sm
                .executeQuery("select passwd from users where username='"
                        + userName + "'");
        if (rs.next()) {
            if (rs.getString(1).equals(passWord)) {
                System.out.println("Login");
                response.sendRedirect("Wel.jsp?userName="+userName);
            } else {
                System.out.println("refuse");
                response.sendRedirect("Login.jsp?errNo=1");
            }
        } else {
        System.out.println("null");
        response.sendRedirect("Login.jsp?errNo=2");
        }

int pageSize = 3;
        int pageNow = 1;
        int pageCount = 0;
        int rowCount = 0;
        String pageN=request.getParameter("pageNow");
        if(pageN !=null){
            pageNow=Integer.parseInt(pageN);
        }
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        Connection ct = DriverManager.getConnection(
                "jdbc:sqlserver://127.0.0.1:1433;databaseName=spdb1", "sa",
                "123456");

        Statement sm = ct.createStatement();
        ResultSet rs = sm.executeQuery("select count(*) from users ");
        if (rs.next()) {
            rowCount = rs.getInt(1);
            if ((rowCount % pageSize) == 0) {
                pageCount = rowCount / pageSize;
            } else {
                pageCount = rowCount / pageSize + 1;
            }
        }
        PreparedStatement ps=ct.prepareStatement("select top "+pageSize+" * from users where userId not in (select top "+pageSize*(pageNow-1)+" userId from users)");
        /*rs = sm.executeQuery("select top" + pageSize
                + " * from users where userId not in(select top"
                + pageSize*(pageNow-1)+ " userId from users)");*/
                rs = ps.executeQuery();
        System.out.println("error");
    %>
    <table border="1" align="center">
        <tr>
            <td>用户Id</td>
            <td>用户名</td>
            <td>密码</td>
            <td>邮箱</td>
            <td>级别</td>
        </tr>
        <%
            while (rs.next()) {
        %>
        <tr>
            <td><%=rs.getInt(1)%></td>
            <td><%=rs.getString(2)%></td>
            <td><%=rs.getString(3)%></td>
            <td><%=rs.getString(4)%></td>
            <td><%=rs.getInt(5)%></td>
        </tr>
        <%
            }
        %>
    </table>
    <%
    //显示超链接
    if(pageNow!=1){
    out.println("<a href=UserWeb/Wel.jsp?pageNow="+(pageNow-1)+">["+"上一页"+"]</a>");
    }
    for(int i=1;i<=pageCount;i++){
    out.println("<a href=UserWeb/Wel.jsp?pageNow="+i+">["+i+"]</a>");
    }
    if(pageNow!=pageCount){
    out.println("<a href=UserWeb/Wel.jsp?pageNow="+(pageNow-1)+">["+"上一页"+"]</a>");
    }
     %>
</body>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值