📄 manageuser.jsp
字号:
<%@ page contentType="text/html;charset=gb2312" import="java.sql.*"%>
<%@ include file="checkadmin.jsp"%>
<%@ include file="top.jsp"%>
<jsp:useBean id="conn" class="dbBean.DBBean" scope="session"/>
<jsp:useBean id="sp" class="spage.ShowPage" scope="session"/>
<html>
<head>
<title>用户管理</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
<script language="javaScript">
function seeUser(userid)
{
window.open('detailuser.jsp?detailid='+userid,'infoWin','height=300,width=700');
}
</script>
</head>
<body background="images/bg01.gif">
<%!
String type="";
String key="";
String sql1="";
String sql2="";
ResultSet rs=null;
ResultSet temp=null;
//每页显示的记录个数
int size = 10;
//当前页号
int p = 1;
//全部的页数
int totalPage = 1;
%>
<%
request.setCharacterEncoding("gb2312");
if(request.getParameter("stype")!=null)
type=request.getParameter("stype");
if(request.getParameter("skey")!=null)
key=request.getParameter("skey");
%>
<p>
<center>
<form action="manageuser.jsp" method="post" name="myform">
请选择查询类别:<select name="stype">
<option value="name" <%if(type!=null) if(type.equals("name")) out.print("selected");%>>用户名</option>
<option value="sex" <%if(type!=null) if(type.equals("sex")) out.print("selected");%>>性别</option>
<option value="phone" <%if(type!=null) if(type.equals("phone")) out.print("selected");%>>电话</option>
</select>
请输入查询关键字:<input type="text" name="skey" size=10>
<input type="submit" value="确定">
</form>
<table width="95%" border bordercolor="blue" align="center" cellpadding="0" cellspacing="0" bordercolorlight="#FFFFFF">
<tr align="center" height="20">
<th background="images/bg04.gif">用户名</th><th background="images/bg04.gif">性别</th><th background="images/bg04.gif">电话</th><th background="images/bg04.gif">地址</th><th background="images/bg04.gif">修改</th><th background="images/bg04.gif">删除</th>
<%
sql1="select * from user";
sql2="select count(*) from user";
if(type!=null && key!=null && !type.equals("") && !key.equals(""))
{
sql1 += " where "+type+" like '%"+key+"%'";
sql2 += " where "+type+" like '%"+key+"%'";
}
sql1+=" order by userid desc";
temp=conn.executeQuery(sql2);
int totalrecord=0;
if(temp.next())
totalrecord = temp.getInt(1);
// 如果是当前页码的整数倍
if(totalrecord % size ==0) totalPage = totalrecord / size;
// 如果最后还空余一页
else totalPage = totalrecord / size + 1;
if(totalPage == 0) totalPage = 1;
temp.close();
try {
if(request.getParameter("p")==null || request.getParameter("p").equals(""))
{
if(session.getAttribute("userp")==null)
p = 1;
else
p = ((Integer)session.getAttribute("userp")).intValue();
}
else
{
p = Integer.parseInt(request.getParameter("p")); session.setAttribute("userp",new Integer(p));
}
}
// 捕获用户从浏览器地址拦直接输入非数字信息而引起的异常
catch(NumberFormatException e) {
p = 1;
}
if(p < 1) p = 1;
if(p > totalPage) p = totalPage;
rs=conn.executeQuery(sql1);
if(rs.next())
out.println(sp.printPage(rs,p,size));
%>
</table>
<form Action="manageuser.jsp" Method="GET">
<%
for(int i=1;i<=totalPage;i++) {
out.println("<a href=manageuser.jsp?p=" + i +">" + i + "</a> ");
}
%>
<p>输入页数:<input type="text" name="p" size="3">
页数:<font color="red"><%=p%>/<%=totalPage%></font>
</form>
</center>
<%
rs.close();
conn.close();
%>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -