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>
Jsp+Model
最新推荐文章于 2020-12-22 19:00:48 发布