请选择 进入手机版 | 继续访问电脑版

好优扒教育

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 10346|回复: 5

JSP分页代码

[复制链接]

55

主题

153

帖子

975

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
975
发表于 2018-5-29 19:36:58 | 显示全部楼层 |阅读模式
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="haou8.com.database.*" %>
<%@ page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>考生列表</title>
<style>
.colum{
width:16%;
height:30px;
float:left;
align:center;
}
.clear{ clear:both}
</style>
</head>
<body>
<%
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
String user_id="";
String user_name="";
String xzb="";
String strSQL="Select * from db_user";
if (request.getParameter("sop")!=null){
  user_id=request.getParameter("user_id");
  user_name=request.getParameter("user_name");
  xzb=request.getParameter("xzb");  
  if(xzb==null)xzb="";
  strSQL+=" where user_id like '%"+user_id +"%'";
  strSQL+=" and user_name like '%"+user_name +"%'";
  strSQL+=" and xzb like '%"+xzb +"%'";
}

%>
<form action="" method=post>
<div class=colum>学号:
<input type=text id=user_id name=user_id value="<%=user_id %>" style="width:80px">
</div>
<div class=colum>姓名:
<input type=text id=user_name name=user_name value="<%=user_name %>" style="width:80px">
</div>
<div class=colum>班级:
<input type=text id=xzb name=xzb value="<%=xzb %>" style="width:80px">
</div>
<div class=colum>
<input type=submit id=sop name=sop value="检索">
</div>
<div class=clear>
<hr color=blue>
</div>
</form>
<div class=colum>序号</div>
<div class=colum>学号</div>
<div class=colum>姓名</div>
<div class=colum>性别</div>
<div class=colum>班级</div>
<div class=colum>操作</div>
<%
//分页处理变量
int PageSize=20;
int PageCount=0;
int Page=1;//当前页码
int PagePrev=1;//前一页
int PageNext=1;//下一页
int rsCount=0; //某条件下的记录条数
int PagePos=1;//定位到某一条记录
%>
<%

ResultSet rs=null;
int i=0;
ExamExecute exec=new ExamExecute();
rs=exec.ExecuteQuery(strSQL);

////////////////////////分页处理/////////////////////
if(request.getParameter("page")!=null) //显示当前页码的处理
  {
   Page=Integer.parseInt(request.getParameter("page"));
   
  }
  else
  {
   Page=1;
  
}
if(rs!=null && rs.next())
{
  rs.last();
  rsCount=rs.getRow();//获得记录总条数
  PageCount=(int)(rsCount/PageSize)+1;
  
  if(Page>=PageCount)
   PageNext=Page;
  else
   PageNext=Page+1;
  if(Page<=1)
   PagePrev=1;
  else
   PagePrev=Page-1;
  PagePos=(Page-1)*PageSize+1;  
  rs.absolute(PagePos);
}
////////////////////分页处理/////////////////////////
i=0;
do{
  i++;
  out.print("<div class=clear></div>");
  out.print("<div class=colum>"+i+"</div>");
  out.print("<div class=colum>"+rs.getString("user_id")+"</div>");
  out.print("<div class=colum>"+rs.getString("user_name")+"</div>");
  out.print("<div class=colum>"+rs.getString("xb")+"</div>");
  out.print("<div class=colum>"+rs.getString("xzb")+"</div>");
  out.print("<div class=colum>");
  out.print("<a href=\"../user.do?action=modi&id="+rs.getString("id")+"\">修改</a>");
  out.print("<a href=\"../user.do?action=del&id="+rs.getString("id")+"\">&nbsp;|删除</a>");
  out.print("<a href=\"../user.do?action=add\">&nbsp;|增加</a>");
  out.print("</div>");
  
  
}while(rs!=null && rs.next() && i<PageSize);
rs.close();
rs=null;
exec.close();
exec=null;
%>
<div class=clear>
<div id=mydiv>
<form action="" method=post id=formpage name=formpage target=_self>
<input type=button id=First name=First value="第一页">
<input type=button id=Prev name=Prev value="前一页">
<input type=button id=Next name=Next value="后一页">
<input type=button id=Last name=Last value="最后一页">
<input type=text id=page name=page value="<%=Page %>" style="width:40px">
<input type=hidden id=sop name=sop value="pagesearch">
<input type=button id=search name=search value="检索">共有<%=rsCount %>条纪录,共<%= PageCount%>页
</form>
</div>
<script language="javascript">
var pageCur=<%=Page %>;
var PagePrev=<%=PagePrev%>;
var PageNext=<%=PageNext%>;
var PageLast=<%=PageCount%>;
function AddElement(obj,name,name_value)
{
var str="<input type=hidden id="+name+ " name="+name+" value="+name_value+">";
obj.innerHTML+=str;
}
AddElement(formpage,"user_id","<%=user_id%>");
AddElement(formpage,"user_name","<%=user_name%>");
AddElement(formpage,"xzb","<%=xzb%>");
function goFirst(){
formpage.page.value=1;
formpage.submit();

}
function GoNext(){
formpage.page.value=PageNext;
formpage.submit();
}
function GoPrev()
{
formpage.page.value=PagePrev;
formpage.submit();
}
function GoLast(){
formpage.page.value=PageLast;
formpage.submit();
}
</script>
</div>
</body>
</html>
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则


关注微信公众号

Archiver|手机版|小黑屋|好优扒教育 ( 皖ICP备14016797号-2

GMT+8, 2019-8-26 17:43 , Processed in 0.093750 second(s), 26 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表