主题:关于分页
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="ss" scope="request" class="OASystem.sqlSystem"/>
<jsp:useBean id="ms" scope="request" class="OASystem.sqlSystem"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
.style1 {
font-size: xx-large;
font-family: "方正姚体";
font-weight: bold;
}
a:link {
color: #000000;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #000000;
}
a:hover {
text-decoration: none;
color: #0033FF;
}
a:active {
text-decoration: none;
color: #000000;
}
-->
</style>
</head>
<body>
<%!
ResultSet rs = null;
ResultSet rsTmp = null;
String sql = "";
int PageSize = 10;
int Page;
int totalPage = 1;
String str = "";
public String ShowOnePage(ResultSet rs,int Page,int PageSize){
str="";
try{
rs.absolute((Page-1)*PageSize+1);
//rs.absolute(21);
}catch(SQLException e){
System.out.println(e.getMessage());
}
for(int iPage=1;iPage<=PageSize;iPage++){
str += RsToGBook(rs);
try{
if(!rs.next())break;
}catch(Exception e){
System.out.println(e.getMessage());
}
}
return str;
}
public String RsToGBook(ResultSet rs){
String tt = "";
try{
tt += "<tr>";
tt += "<td>"+rs.getString("WorkerId")+"</td>";
tt += "<td>"+rs.getString("WorkerName")+"</td>";
tt += "<td>"+rs.getString("GroupId")+"</td>";
tt += "<td>"+rs.getString("DepartementId")+"</td>";
tt += "<td>"+rs.getString("Sex")+"</td>";
tt += "<td>"+rs.getString("Leader")+"</td>";
tt += "<td>操作</td>";
tt += "</tr>";
}catch(SQLException e){
System.out.println(e.getMessage());
}
return tt;
}
%>
<div align="center">
<table width="746" height="116" border="0" cellspacing="0">
<tr>
<td width="174" background="../images/atwork_hpSpot_tier1c_F.jpg"> </td>
<td width="568" background="../images/ff.jpg"><div align="center" class="style1">人事管理信息
</div></td>
</tr>
</table>
<p> </p>
<hr>
<table width="746" border="0" cellspacing="0">
<%
try{
rs = ss.eq("SELECT * FROM DD_Worker");
}catch(java.lang.NumberFormatException e){
out.println(e.getMessage());
}
%>
<tr bgcolor="#F0F1F5">
<td width="99"><div align="center">员工工号</div></td>
<td width="99"><div align="center">员工姓名</div></td>
<td width="99"><div align="center">部门</div></td>
<td width="99"><div align="center">组别</div></td>
<td width="99"><div align="center">性别</div></td>
<td width="99"><div align="center">职务</div></td>
<td width="107"><div align="center">操作</div></td>
</tr>
<%
rsTmp = ms.eq("SELECT COUNT(*) FROM DD_Worker");
rsTmp.next();
int totalRecord = rsTmp.getInt(1);
if(totalRecord%PageSize==0){
totalPage = totalRecord/PageSize;
}else{
totalPage = (int)Math.floor(totalRecord/PageSize)+1;
}
if(totalPage==0){
totalPage=1;
}
rsTmp.close();
try{
if(request.getParameter("Page")==null||request.getParameter("Page").equals("")){
Page = 1;
}else{
Page = Integer.parseInt(request.getParameter("Page"));
}
}catch(java.lang.NumberFormatException e){
Page = 1;
}
if(Page<1){Page=1;}
if(Page>totalPage){Page=totalPage;}
out.println(ShowOnePage(rs,Page,PageSize));
%>
<tr bgcolor="#F0F1F5">
<td><div align="right">共有员工</div></td>
<td><div align="left"><%=totalRecord%>个</div></td>
<td><div align="center"><a href="AddPerson.jsp?Page=<%=Page-1%>">上一页</a></div></td>
<td><div align="center">第<%=Page%>页</div></td>
<td><div align="center"><a href="AddPerson.jsp?Page=<%=Page+1%>">下一页</a></div></td>
<td><div align="right">共有</div></td>
<td width="107"><div align="left"><%=totalPage%>页</div></td>
</tr>
</table>
<%//rs.close();rsTmp.close();%>
<hr>
<p> </p>
</div>
</body>
</html>
以上程序运行正常,就是当点击上一页和下一页是,页数变化,但是记录还是显示1到10个
不知道问题在哪里?望那位仁兄加以指点.
还有一个问题:
当远程访问我的论坛时,提交内容会受到限制,字数多则提交失败不知道何原因,在局域网中没有此问题发生?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="ss" scope="request" class="OASystem.sqlSystem"/>
<jsp:useBean id="ms" scope="request" class="OASystem.sqlSystem"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
.style1 {
font-size: xx-large;
font-family: "方正姚体";
font-weight: bold;
}
a:link {
color: #000000;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #000000;
}
a:hover {
text-decoration: none;
color: #0033FF;
}
a:active {
text-decoration: none;
color: #000000;
}
-->
</style>
</head>
<body>
<%!
ResultSet rs = null;
ResultSet rsTmp = null;
String sql = "";
int PageSize = 10;
int Page;
int totalPage = 1;
String str = "";
public String ShowOnePage(ResultSet rs,int Page,int PageSize){
str="";
try{
rs.absolute((Page-1)*PageSize+1);
//rs.absolute(21);
}catch(SQLException e){
System.out.println(e.getMessage());
}
for(int iPage=1;iPage<=PageSize;iPage++){
str += RsToGBook(rs);
try{
if(!rs.next())break;
}catch(Exception e){
System.out.println(e.getMessage());
}
}
return str;
}
public String RsToGBook(ResultSet rs){
String tt = "";
try{
tt += "<tr>";
tt += "<td>"+rs.getString("WorkerId")+"</td>";
tt += "<td>"+rs.getString("WorkerName")+"</td>";
tt += "<td>"+rs.getString("GroupId")+"</td>";
tt += "<td>"+rs.getString("DepartementId")+"</td>";
tt += "<td>"+rs.getString("Sex")+"</td>";
tt += "<td>"+rs.getString("Leader")+"</td>";
tt += "<td>操作</td>";
tt += "</tr>";
}catch(SQLException e){
System.out.println(e.getMessage());
}
return tt;
}
%>
<div align="center">
<table width="746" height="116" border="0" cellspacing="0">
<tr>
<td width="174" background="../images/atwork_hpSpot_tier1c_F.jpg"> </td>
<td width="568" background="../images/ff.jpg"><div align="center" class="style1">人事管理信息
</div></td>
</tr>
</table>
<p> </p>
<hr>
<table width="746" border="0" cellspacing="0">
<%
try{
rs = ss.eq("SELECT * FROM DD_Worker");
}catch(java.lang.NumberFormatException e){
out.println(e.getMessage());
}
%>
<tr bgcolor="#F0F1F5">
<td width="99"><div align="center">员工工号</div></td>
<td width="99"><div align="center">员工姓名</div></td>
<td width="99"><div align="center">部门</div></td>
<td width="99"><div align="center">组别</div></td>
<td width="99"><div align="center">性别</div></td>
<td width="99"><div align="center">职务</div></td>
<td width="107"><div align="center">操作</div></td>
</tr>
<%
rsTmp = ms.eq("SELECT COUNT(*) FROM DD_Worker");
rsTmp.next();
int totalRecord = rsTmp.getInt(1);
if(totalRecord%PageSize==0){
totalPage = totalRecord/PageSize;
}else{
totalPage = (int)Math.floor(totalRecord/PageSize)+1;
}
if(totalPage==0){
totalPage=1;
}
rsTmp.close();
try{
if(request.getParameter("Page")==null||request.getParameter("Page").equals("")){
Page = 1;
}else{
Page = Integer.parseInt(request.getParameter("Page"));
}
}catch(java.lang.NumberFormatException e){
Page = 1;
}
if(Page<1){Page=1;}
if(Page>totalPage){Page=totalPage;}
out.println(ShowOnePage(rs,Page,PageSize));
%>
<tr bgcolor="#F0F1F5">
<td><div align="right">共有员工</div></td>
<td><div align="left"><%=totalRecord%>个</div></td>
<td><div align="center"><a href="AddPerson.jsp?Page=<%=Page-1%>">上一页</a></div></td>
<td><div align="center">第<%=Page%>页</div></td>
<td><div align="center"><a href="AddPerson.jsp?Page=<%=Page+1%>">下一页</a></div></td>
<td><div align="right">共有</div></td>
<td width="107"><div align="left"><%=totalPage%>页</div></td>
</tr>
</table>
<%//rs.close();rsTmp.close();%>
<hr>
<p> </p>
</div>
</body>
</html>
以上程序运行正常,就是当点击上一页和下一页是,页数变化,但是记录还是显示1到10个
不知道问题在哪里?望那位仁兄加以指点.
还有一个问题:
当远程访问我的论坛时,提交内容会受到限制,字数多则提交失败不知道何原因,在局域网中没有此问题发生?