代碼執行個體:JSP分頁來源程式

來源:互聯網
上載者:User
js|程式|分頁

<%@ page contentType="text/html; charset=gb2312" language="java"%>

<%@ page import = "java.util.*"%>
<%@ page import = "java.io.*"%>
<%@ page import = "java.sql.*"%>
<html>
<head>
<title>教師資訊查詢</title>
<style type="text/css">
<!--
.style1 {
 font-family: "華文行楷";
 color: #FFFFFF;
}
-->
</style>
<link href="default.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style6 {
 color: #000000;
 font-size: 24px;
}
.style9 {font-size: 24px}
-->
</style>
</head>
<body bgcolor="#ffffff">
<%session.getAttribute("a_name");%>
<h1 align="center" class="style1 style6 style9">教師資訊查詢</h1>
<hr />
<jsp:useBean id="tmessgeBean" scope="page" class="computer.sqlbean"/>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr align="center" bgcolor="#00FFFF">
<td colspan="5" bgcolor="#666666" class="style4"><div align="right"><a href="index.html">返回首頁</a></div></td>
</tr>
<tr align="center" bgcolor="#999999">
  <td class="style4">教號</td>
  <td class="style4">姓名</td>
  <td class="style4">系別</td>
  <td class="style4">專業</td>
  <td class="style4">操作選項</td>
</tr>
<%
request.setCharacterEncoding("gb2312");
int nowPages;//當前頁
int pages;//請求頁數
int countPerPage = 10 ; //每頁顯示條數
int pageCount;//總頁數
int recordCount=tmessgeBean.getCounter("select count(*) from dysf_teacher ");

pageCount = (int)Math.ceil((recordCount + countPerPage-1) / countPerPage);//算出總頁數
if(request.getParameter("pages") == null){

pages = 1;
}else{
pages = new Integer(request.getParameter("pages")).intValue();
}


if(pages > pageCount){
nowPages = 1;
}else{
nowPages = pages;
}

ResultSet rs = tmessgeBean.executeQuery("Select top "+ countPerPage +" * from dysf_teacher where id not in (select top "+ (nowPages-1)*countPerPage +" id from dysf_teacher order by id desc) order by id desc ");
while(rs.next()){
String ID = rs.getString("id");
String tdepartment = rs.getString("department");
String tspecial = rs.getString("special");
String tname = rs.getString("name");
%>
<tr>
<td width="20%" align="center"><%= ID %></td>
<td width="20%"><div align="center"></div>
  <div align="center"><%= tname %></div></td>
<td width="20%"><div align="center"></div>
  <div align="center"><%= tdepartment %></div></td>
<td width="20%"><div align="center"></div>
  <div align="center"><%= tspecial %></div></td>
<td align="center"><a href="atdelete.jsp?ID=<%= ID %>">刪除</a></td>
</tr>
<%
}
rs.close();
%>
<tr align="right">
<td colspan="5">共有<font color=red><%= recordCount %></font>條記錄 當前<font color=red><%= nowPages %>/<%= pageCount %></font>頁 
<% if(pageCount > 1){ %>
<% if(pages > 1){%>
<a href="">首頁</a>
<%}if(pages < pageCount){%>
<a href="?pages=<%= nowPages+1 %>">下一頁</a>
<%}if(pages != 1){%>
<a href="?pages=<%= nowPages - 1 %>">上一頁</a>
<%}%>
<a href="?pages=<%= pageCount %>">尾頁</a>
<% } %>跳轉到
<select name="pages" >
<% for(int i=1;i<=pageCount;i++){%>
<option value="<%= i %>" <% if(nowPages == i){%>selected<% } %>><%= i %></option>
<% } %>
</select>頁</td>
</tr>
</table>
<hr />
</body>
</html> 



相關文章

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。