使用jsp实现最基本的翻页:
Java.trssearcher.ArticleBean"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="UTF-8"%>
检索
<script type="text/javascript">
function validate1() {
var page = document.forms[0].page.value;
if (page.length
<%
String str = request.getParameter("keyWords");
String strWhere = "标题=" + str + " or 正文=" + str;
int intPage = 0; //待显示页码
//取得待显示页码
String strPage = request.getParameter("page");
if (strPage == null)//表明在QueryString中没有page这一个参数,此时显示第一页数据
{
intPage = 1;
} else
{
intPage = java.lang.Integer.parseInt(strPage);
if (intPage < 1)
{
intPage = 1;
}
}
sResult = searchBean.searchList(strWhere, intPage);
int intRowCount = (int) sResult.getTotal();
out.println("检索时间:" + sResult.getCosttime() + "
");
out.println("记录总数:" + intRowCount + "
" + "
");
int PgFirst = (intPage - 1) * 20 + 1; //待显示页数第一条信息条
List articleList = sResult.getArticleBeans(); //获取该页的标题列表对象
int intPageCount = sResult.getPageNum(); //获取总页数
for (int i = 0; i < articleList.size(); i++)
{
ArticleBean article = new ArticleBean();
article = articleList.get(i);
String strTitle = article.getTitle();
String rowid = article.getRowid();
out.println("第" + PgFirst + "条:" + "
");
%>
标题:
">
<%
out.println("
" + "日期:" + article.getDate() + "
");
PgFirst++;
}
%>
第页/共页
共条记录 <%
if (intPage < 2)
{
out.print("首页|上一页");
} else
{
%> &keyWords=">首页 | &keyWords=">上一页 <%
}
%> | <%
if ((intPageCount - intPage) < 1)
{
out.print("下一页 | 尾页");
} else
{
%> &keyWords=">下一页
| &keyWords=">尾页
<%
}
%>
">
">
可以参考使用了jstl后的效果,http://blog.csdn.net/redeagle_gbf/article/details/17168131对比发现使用jstl后代码量和使用效果都要好很多
如果不爱-请你走开-别让我痴痴的等待