代码实例:JSP分页源程序

2016-02-19 13:17 4 1 收藏

下面是个代码实例:JSP分页源程序教程,撑握了其技术要点,学起来就简单多了。赶紧跟着图老师小编一起来看看吧!

【 tulaoshi.com - Web开发 】

%@ 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();
}

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)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" 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

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)

来源:http://www.tulaoshi.com/n/20160219/1603690.html

延伸阅读
标签: Web开发
/**这是管理user信息的类 文件名为onLineUser.java */ import javax.servlet.http.*; import javax.servlet.*; import java.util.*; public class onLineUser implements HttpSessionBindingListener { public onLineUser(){ } private Vector users=new Vector(); public int getCount(){ users.trimToSize(); return users.cap...
标签: Web开发
image.jsp 代码如下: %@ page language="java" import="java.util.*" pageEncoding="GBK"% % String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; % %@ page contentType="image/jpeg" import="java.awt.*,java.awt.image.*,java.util...
import sun.net.ftp.*; import sun.net.*; import java.awt.*; import java.awt.event.*; import java.applet.*; import java.io.*; public class FtpApplet extends Applet { FtpClient aftp; DataOutputStream outputs ; TelnetInputStream ins; TelnetOutputStream outs; TextArea lsArea; Label LblPrompt; Button BtnConn; Button Bt...
代码如下: /* *@curentpage 当前页 *@pagesize 每页记录数 *@TableName 表名 *@key 主键(自动排序) *@where 查询条件 1)空为 null 2)有查询条件不要带where *@order '0'表示 desc '1'是asc *@pageCount 总页数 */ create procedure Page @currentpage int,@pagesize int, @TableName varchar(30),@key varchar(30), @where...
标签: Web开发
我的一个详细的jsp分页程序!(oracle+jsp+apache) 一 前提 希望最新的纪录在开头给你的表建立查询: 表:mytable 查询:create or replace view as mytable_view from mytable order by id desc 其中,最好使用序列号create sequence mytable_sequence 来自动增加你的纪录id号 二 源程序 %String sConn="...

经验教程

870

收藏

77
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部