?? delete.jsp
字號:
<%@ page contentType="text/html;charset=gb2312" import="java.sql.*"%>
<%@ include file="checkadmin.jsp"%>
<jsp:useBean id="conn" class="dbBean.DBBean" scope="session"/>
<%!
//每頁顯示的記錄個數
int size = 8;
//當前頁號
int p = 1;
//全部的頁數
int totalPage = 1;
String str = "";
//顯示頁號為p的一頁
public String printPage(ResultSet rs, int p, int size)
{
str = "";
//將訪問游標定位到頁號為p的頁要顯示的第一條記錄的位置
try {
for(int k=0;k<(p-1)*size;k++)
rs.next();
}
catch(SQLException e) { }
for(int iPage=1; iPage<=size; iPage++) {
str += printRow(rs,iPage);
try {
if(!rs.next()) break;
}
catch(Exception e) { }
}
return str;
}
//顯示單行記錄
public String printRow( ResultSet rs ,int i)
{
String temp = "";
try {
if(i%2==1)
temp+="<tr bgcolor='#e7e7e7'>";
else
temp+="<tr bgcolor='#f7f7f7'>";
String id=rs.getString("id");
temp+="<td><a href='update.jsp?updateid="+id+"' target='left'>"+id+"</a></td>";
temp+="<td>"+rs.getString("name")+"</td>";
temp+="<td>"+rs.getString("sex")+"</td>";
temp+="<td>"+rs.getString("age")+"</td>";
temp+="<td>"+rs.getString("email")+"</td>";
temp+="<td align='center'><input type='checkbox' name='isdel' value='"+id+"'></td>";
temp += "</TR>";
}
catch(SQLException e) { }
return temp;
}
%>
<%
ResultSet rs=null;
rs = conn.executeQuery("select * from user order by id");
%>
<center>
<form method="post" action="dealdelete.jsp">
<table border="1" borderColorDark="#ffffec" borderColorLight="#5e5e00" width="100%">
<tr bgcolor="#cccccc" align="center">
<th>id號</th><th>用戶名</th><th>性別</th><th>年齡</th><th>電子郵件</th><th>是否刪除</th>
<%
ResultSet rsTmp=null;
rsTmp = conn.executeQuery("select count(*) as mycount from user");
int totalrecord=0;
if(rsTmp.next())
totalrecord = rsTmp.getInt("mycount");
// 如果記錄數是頁數的整數倍
if(totalrecord % size ==0) totalPage = totalrecord / size;
// 如果最后還空余一頁
else totalPage = (int) Math.floor( totalrecord / size ) + 1;
if(totalPage == 0) totalPage = 1;
rsTmp.close();
try {
if(request.getParameter("p")==null|| request.getParameter("p").equals(""))
{
if(session.getAttribute("deletep")==null)
p = 1;
else
p = ((Integer)session.getAttribute("deletep")).intValue();
}
else
{
p = Integer.parseInt(request.getParameter("p")); session.setAttribute("deletep",new Integer(p));
}
}
// 捕獲用戶從瀏覽器地址攔直接輸入非數字信息而引出的異常
catch(NumberFormatException e) { p = 1;}
if(p < 1) p = 1;
if(p > totalPage) p = totalPage;
if(rs.next())
out.println(printPage(rs,p,size));
%>
</table>
<p>
<input type="submit" value="刪除">
<input type="reset" value="重置">
</form>
<form Action="delete.jsp" Method="GET">
<%
for(int i=1;i<=totalPage;i++) {
out.println("<a href=delete.jsp?p=" + i + ">" + i + "</a> ");
}
%>
<p>輸入頁數:<input type="text" name="p" size="3">
頁數:<font color="red"><%=p%>/<%=totalPage%></font>
</p>
</form>
</center>
<%
rs.close();
conn.close();
%>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -