jsp 分页显示问题

matchchrist matchchrist 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<%@ page import="java.io.*,java.awt.Image,java.awt.image.*,com.sun.image.codec.jpeg.*,java.sql.*,java.util.*"%>
<%@ page import="java.text.*,java.util.Date"%>
<% request.setCharacterEncoding("gb2312"); %>
<jsp:useBean id="getS" class="com.Login.getConnect"></jsp:useBean>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>分页显示数据库信息</title>
</head>
<body>
<div align="center"><strong>分页显示数据库记录</strong></div>
<br><hr>
<table width="800" border="1" align="center">
<tr>
<td>序号</td><td>评分时间</td><td> 评分人</td><td> 被评分人</td><td>能力评分(10)</td><td>态度评分(5)</td>
</tr>
<%

String username=(String)session.getAttribute("username");
String userrole=(String)session.getAttribute("userrole");
String userid=(String)session.getAttribute("userid");
String yuefen=request.getParameter("yuefen");
try
{

Statement stmt=getS.getS();
String upd="";
if("admin".equals(userrole))
{
upd="select * from yuedu_pf where kaohe_shijian='"+yuefen+"' ";

}
else
upd="select * from yuedu_pf where kaohe_shijian='"+yuefen+"' and pf_ren='"+username+"' ";
System.out.println(upd);
ResultSet rs=stmt.executeQuery(upd);
int intPageSize; //一页显示的记录数
int intRowCount; //记录的总数
int intPageCount; //总页数
int intPage; //待显示的页码
String strPage;
int i;
//设置一页显示的记录数
intPageSize=9;
//取得待显示的页码
strPage=request.getParameter("page");
//判断strPage是否等于null,如果是,显示第一页数据
if(strPage==null)
{
intPage=1;
}else{
//将字符串转换为整型
intPage=java.lang.Integer.parseInt(strPage);
}
if(intPage<1)
{
intPage=1;
}
//获取记录总数
rs.last();
intRowCount=rs.getRow();
//计算机总页数
intPageCount=(intRowCount+intPageSize-1)/intPageSize;
//调整待显示的页码
if(intPage>intPageCount) intPage=intPageCount;
if(intPageCount>0)
{
//将记录指针定位到待显示页的第一条记录上
rs.absolute((intPage-1)*intPageSize+1);
}
//下面用于显示数据
i=0;
while(i<intPageSize && !rs.isAfterLast())
{
%>
<tr>
<td ><%= i %></td>
<td ><%= rs.getString("kaohe_shijian") %></td>
<td ><%= rs.getString("pf_ren") %></td>
<td ><%= rs.getString("bei_pf_ren") %></td>
<td ><%= rs.getString("pf_nl") %></td>
<td ><%= rs.getString("pf_td") %></td>
</tr>
<%
rs.next();
i++;
}

%>
<div align="center">
共<%=intRowCount%>个记录,分<%=intPageCount%>页显示,当前页是:第<%=intPage%>页
<%
for(int j=1;j<=intPageCount;j++)
{
out.print("  <a href='pingfen_chaxun_tj.jsp?page="+j+"'>"+j+"</a>");

}
%>
</div>
<%
}
catch(Exception e)
{
e.printStackTrace();
}
%>
</table>
</body>
</html>

分页显示代码

...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
matchchrist
Web 开发 81,108 成员 341,721 内容