首页 > 开发 > JSP > 正文

代码实例:JSP分页源程序

2020-02-05 13:48:56
字体:
来源:转载
供稿:网友

<%@ 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>条记录&nbsp;当前<font color=red><%= nowpages %>/<%= pagecount %></font>页&nbsp;
<% 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" onchange="javascript:this.form.submit();">
<% for(int i=1;i<=pagecount;i++){%>
<option value="<%= i %>" <% if(nowpages == i){%>selected<% } %>><%= i %></option>
<% } %>
</select>页</td>
</tr>
</table>
<hr />
</body>
</html> 



收集最实用的网页特效代码!

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表