2个回答
展开全部
页面分页用javascript就行,网上有现成的控件下载.....后台分页的话,用数据库的语句吧......我做过在jsp页面上涌java代码分页,但这样做很麻烦,效果也不好.,不推荐你用
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<%@page contentType="text/html; charset=UTF-8" language="java" import ="java.util.*" pageEncoding="GBK"%>
<%
int intPageSize = 20; //每页显示行数
int intRowCount = 93; //总行数
int intPageCount = 1; //总页数
int intPage; //当前页的页数
int i = 0;
String[] strTd1 = new String[intRowCount];
String[] strTd2 = new String[intRowCount];
for(i=0;i<intRowCount;i++)
{
strTd1[i] = "第"+(i+1)+"行,第1列";
strTd2[i] = "第"+(i+1)+"行,第2列";
}
String strPage = request.getParameter("intPage");
if(strPage==null)
{
intPage = 1;
}else{
intPage = java.lang.Integer.parseInt(strPage);
if(intPage<1)
{
intPage = 1;
}
}
intPageCount = (intRowCount+intPageSize-1) / intPageSize;
if(intPage>intPageCount)
{
intPage = intPageCount;
}
%>
<html><body><table border="1px">
<%
if(intPage<intPageCount)
{
for(i=(intPage-1)*intPageSize;i<intPage*intPageSize;i++){
%><tr><td><%=strTd1[i]%></td><td><%=strTd2[i]%></td></tr><%
}
}
if(intPage == intPageCount)
{
for(i=(intPage-1)*intPageSize;i<intRowCount;i++){
%><tr><td><%=strTd1[i]%></td><td><%=strTd2[i]%></td></tr><%
}
}
%>
</table>
<form name="this_form" method="post"></form>
<table><tr><td> </td></tr>
<tr><td>
第<%=intPage%>页 共<%=intPageCount%>页
<%if(intPage<intPageCount){
%>
<input type="button" value="下一页" onClick="this_form.action='test.jsp?intPage=<%=intPage+1%>'; this_form.submit();">
<%}
if(intPage>1)
{
%>
<input type="button" value="上一页" onClick="this_form.action='test.jsp?intPage=<%=intPage-1%>'; this_form.submit();">
<%}%>
</td></tr></table>
<%
int intPageSize = 20; //每页显示行数
int intRowCount = 93; //总行数
int intPageCount = 1; //总页数
int intPage; //当前页的页数
int i = 0;
String[] strTd1 = new String[intRowCount];
String[] strTd2 = new String[intRowCount];
for(i=0;i<intRowCount;i++)
{
strTd1[i] = "第"+(i+1)+"行,第1列";
strTd2[i] = "第"+(i+1)+"行,第2列";
}
String strPage = request.getParameter("intPage");
if(strPage==null)
{
intPage = 1;
}else{
intPage = java.lang.Integer.parseInt(strPage);
if(intPage<1)
{
intPage = 1;
}
}
intPageCount = (intRowCount+intPageSize-1) / intPageSize;
if(intPage>intPageCount)
{
intPage = intPageCount;
}
%>
<html><body><table border="1px">
<%
if(intPage<intPageCount)
{
for(i=(intPage-1)*intPageSize;i<intPage*intPageSize;i++){
%><tr><td><%=strTd1[i]%></td><td><%=strTd2[i]%></td></tr><%
}
}
if(intPage == intPageCount)
{
for(i=(intPage-1)*intPageSize;i<intRowCount;i++){
%><tr><td><%=strTd1[i]%></td><td><%=strTd2[i]%></td></tr><%
}
}
%>
</table>
<form name="this_form" method="post"></form>
<table><tr><td> </td></tr>
<tr><td>
第<%=intPage%>页 共<%=intPageCount%>页
<%if(intPage<intPageCount){
%>
<input type="button" value="下一页" onClick="this_form.action='test.jsp?intPage=<%=intPage+1%>'; this_form.submit();">
<%}
if(intPage>1)
{
%>
<input type="button" value="上一页" onClick="this_form.action='test.jsp?intPage=<%=intPage-1%>'; this_form.submit();">
<%}%>
</td></tr></table>
参考资料: http://hi.baidu.com/online_ghost/blog/item/83a712b02117cbb6d8335a59.html
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询