📄 listuserpage.jsp
字号:
<%-- listUserPage.jsp分页显示程序代码 --%>
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.util.Calendar" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.SQLException" %>
<%
//取得查询条件值
request.setCharacterEncoding("gb2312");
String username=request.getParameter("username");
String region=request.getParameter("region");
int months=Integer.parseInt(request.getParameter("months"));
String pageId=request.getParameter("pageId");
//
Calendar nowCalendar=Calendar.getInstance();
String nowDate=nowCalendar.get(Calendar.YEAR)+"/"+
(nowCalendar.get(Calendar.MONTH)+1)+"/"+
nowCalendar.get(Calendar.DATE);
nowCalendar.add(Calendar.MONTH,-months);
String beforeDate=nowCalendar.get(Calendar.YEAR)+"/"+
(nowCalendar.get(Calendar.MONTH)+1)+"/"+
nowCalendar.get(Calendar.DATE);
//out.println(nowDate+" "+beforeDate);
//建立数据库连接并执行数据分页查询
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
int count=0; //记录总数
int totalPageCount=0; //总页数
int perPageCount=15; //每页显示的记录条数
int currentPage=1; //当前页号
if(pageId!=null){
currentPage=Integer.parseInt(pageId);
}
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc:odbc:datasource_suit","sa","710318");
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); //滚动游标
String strSQL="select username,sex,age,region,email,marriage,regdate from t_userInfo where ";
strSQL+="username like '%"+username+"%' and ";
strSQL+="region='"+region+"' and ";
strSQL+="regdate>='"+beforeDate+"' and regdate<='"+nowDate+"' order by regdate desc";
//out.println(strSQL);
rs=stmt.executeQuery(strSQL);
rs.last(); //移到末尾
count=rs.getRow();
totalPageCount=count/perPageCount; //计算分页的总数目
if(count>totalPageCount*perPageCount){ //若有剩余记录,分页总数目加1.
totalPageCount++;
}
if(currentPage>totalPageCount||currentPage<=0){ //如果请求的页面号不在(1,totalPageCount)范围之内
currentPage=1;
}
int currentIndex=(currentPage-1)*perPageCount+1;
%>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>姓名</title>
</head>
<body>
<p align="center"><u><b><font face="仿宋_GB2312" size="3" color="#0000FF">会 员 资 料 表(共<%=count%>个会员)</b></u></p>
<div align="center">
<center>
<table border="0" width="100%" height="25">
<tr>
<td width="118" height="1" bgcolor="#EAF4F4" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF">姓名</font></td>
<td width="81" height="1" bgcolor="#EAF4F4" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF">性别</font></td>
<td width="166" height="1" bgcolor="#EAF4F4" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF">年龄</font></td>
<td width="95" height="1" bgcolor="#EAF4F4" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF">地区</font></td>
<td width="185" height="1" bgcolor="#EAF4F4" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF">email</font></td>
<td width="80" height="1" bgcolor="#EAF4F4" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF">婚姻</font></td>
<td width="162" height="1" bgcolor="#EAF4F4" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF">入会日期</font></td>
<%
rs.absolute(currentIndex); //移到第一笔记录处,然后显示该笔记录。
%>
<tr>
<td width="118" height="1" bgcolor="#FFD9FF" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF"><%=rs.getString("username")%></font></td>
<td width="81" height="1" bgcolor="#FFD9FF" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF"><%if(rs.getInt("sex")==1){out.print("男");}else{out.print("女");}%></font></td>
<td width="166" height="1" bgcolor="#FFD9FF" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF"><%=rs.getString("age")%></font></td>
<td width="95" height="1" bgcolor="#FFD9FF" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF"><%=rs.getString("region")%></font></td>
<td width="185" height="1" bgcolor="#FFD9FF" align="center"><font face="Arial" size="3" color="#0000FF"><%=rs.getString("email")%></font></td>
<td width="80" height="1" bgcolor="#FFD9FF" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF"><%if(rs.getInt("marriage")==1){out.print("已婚");}else{out.print("未婚");}%></font></td>
<td width="162" height="1" bgcolor="#FFD9FF" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF"><%=rs.getDate("regdate")%></font></td>
</tr>
<%
int i=0; //循环控制计数
while(rs.next()){ //循环显示下一笔会员资料
%>
<tr>
<td width="118" height="1" bgcolor="#FFD9FF" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF"><%=rs.getString("username")%></font></td>
<td width="81" height="1" bgcolor="#FFD9FF" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF"><%if(rs.getInt("sex")==1){out.print("男");}else{out.print("女");}%></font></td>
<td width="166" height="1" bgcolor="#FFD9FF" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF"><%=rs.getString("age")%></font></td>
<td width="95" height="1" bgcolor="#FFD9FF" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF"><%=rs.getString("region")%></font></td>
<td width="185" height="1" bgcolor="#FFD9FF" align="center"><font face="Arial" size="3" color="#0000FF"><%=rs.getString("email")%></font></td>
<td width="80" height="1" bgcolor="#FFD9FF" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF"><%if(rs.getInt("marriage")==1){out.print("已婚");}else{out.print("未婚");}%></font></td>
<td width="162" height="1" bgcolor="#FFD9FF" align="center"><font face="仿宋_GB2312" size="3" color="#0000FF"><%=rs.getDate("regdate")%></font></td>
</tr>
<%
i++;
if(i>perPageCount-1) break; //跳出while循环(共14行)
} //while循环的结束符
}catch(Exception e){
out.println("查询失败.");
}
finally{
try{
if(stmt!=null){
stmt.close();
}
if(conn!=null){
conn.close();
}
if(rs!=null){
rs.close();
}
}catch(SQLException sqle){}
}
%>
</table>
</center>
</div>
<%
String firstLink,lastLink,preLink,nextLink;
firstLink="listUserPage.jsp?username="+username+"®ion="+region+"&months="+months+"&pageId=1";
lastLink="listUserPage.jsp?username="+username+"®ion="+region+"&months="+months+"&pageId="+totalPageCount;
//上一页调用的页面
if(currentPage>1){
preLink="listUserPage.jsp?username="+username+"®ion="+region+"&months="+months+"&pageId="+(currentPage-1);
}
else{
preLink=firstLink;
}
//下一页调用的页面
if(currentPage<=totalPageCount-1){
nextLink="listUserPage.jsp?username="+username+"®ion="+region+"&months="+months+"&pageId="+(currentPage+1);
}
else{
nextLink=firstLink;
}
%>
<form method="POST" action="jump.jsp">
<%
String preUrl="listUserPage.jsp?username="+username+"®ion="+region+"&months="+months;
%>
<p align="center"><font face="仿宋_GB2312">共<%=totalPageCount%>页|<font face="仿宋_GB2312">当前第<%=currentPage%>页 |<a href=<%=firstLink%>>首页</a>|<a href=<%=preLink%>>上一页</a>|<a href=<%=nextLink%>>下一页</a>|<a href=<%=lastLink%>>尾页</a>|
转到<input type="text" name="goPage" size="6"><input type="hidden" value="<%=preUrl%>" name="preUrl"><input type="submit" value="Go" name="go"></font></p>
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -