首页| 新闻| 娱乐| 游戏| 科普| 文学| 编程| 系统| 数据库| 建站| 学院| 产品| 网管| 维修| 办公| 热点
今天小编给大家分享一篇JSP分页代码的深度解析,感兴趣的朋友跟小编一起来了解一下吧!
有热心网友回复:
str += " 转到";
1.以下是实现分页的类PageResultSet
package page.bean;
public class PageResultSet {
* 分页数据
private Collection data = null;
* 当前页
private int curPage;
* 每页显示的记录数
private int pageSize;
* 记录行数
private int rowsCount;
* 页数
private int pageCount;
this.data = data;
this.pageSize = 10;
this.pageCount = (int) Math.ceil((double) rowsCount / pageSize);
public PageResultSet(Collection data, int curPage) {
this.curPage = curPage;
this.rowsCount = data.size();
}
this.pageSize = pageSize;
/**
*
*/
return curPage;
return pageSize;
return rowsCount;
return pageCount;
return 1;
return (curPage - 1
return (curPage + 1 > pageCount) ? pageCount : curPage + 1;
return (curPage == 1) ? true : false;
return (curPage == pageCount) ? true : false;
/** * 获取当前页数据
* @return Collection
public Collection getData() {
if (data != null) {
int end = 0;
end = rowsCount;
end = start + pageSize;
ArrayList arrayData = null;
Vector vectorData = null;
if (data instanceof ArrayList) {
isArray = true;
vectorData = (Vector) data;
if (isArray) {
} else {
return curData;
String temp = "";
temp = "?";
temp = "&";
String str = "
for (int i = 1; i
if (i == curPage)
str += "
";
else
return str;
2.一下是Action
复制代码 代码如下:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
package struts.action;
import java.util.Collection;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import page.bean.DatabaseConn;
import page.bean.PageResultSet;
import page.bean.ContactBO;
import struts.form.LoginForm;
* MyEclipse Struts
* Creation date: 04-02-2008
* XDoclet definition:
* @struts.action path="/login" name="loginForm" input="/login.jsp" scope="request" validate="true"
* @struts.action-forward name="sss" path="/index.jsp"
public class LoginAction extends Action {
* Generated Methods
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;
ContactBO userBO=new ContactBO();
//先从业务处理逻辑类中取出数据(ArrayList或Vector格式)
Collection data;
try {
data = userBO.findContact(DatabaseConn.getConnection());
//再得到当前页curPage和每页记录数pageSize
//int curPage = Integer.parseInt((String)request.getParameter("cur_page"));
int curPage = 1;
String cur = request.getParameter("cur_page");
System.out.println("--------------: "+cur);
if(cur!=null && cur !=""){
curPage = new Integer(cur).intValue();
int pageSize=10;
//然后生成PageResultSet对象
PageResultSet dataList = new PageResultSet(data, curPage, pageSize);
request.setAttribute("usersList", dataList);
return mapping.findForward("sss");
} catch (Exception e) {
e.printStackTrace();
return mapping.getInputForward();
3.以下是显示分页的页面
pageEncoding="gb2312"%>
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
PageResultSet pageResultSet = (PageResultSet) request.getAttribute("usersList");
ArrayList usersList = (ArrayList) pageResultSet.getData();
for (int i = 0; i
Contact co = (Contact) usersList.get(i);
以上就是JSP分页代码的深度解析,想必都了解了吧,更多相关内容请继续关注错新技术频道。
练就火眼金睛 十一种常见电脑
打印机共享提示“操作无法完成
如何查找有故障的配件
回眸一笑百魅生,六宫粉黛无颜色
岁月静美,剪一影烟雨江南
芜湖有个“松鼠小镇”
小满:小得盈满,一切刚刚好!
一串串晶莹剔透的葡萄,像一颗颗宝石挂在藤
正宗老北京脆皮烤鸭
人逢知己千杯少,喝酒搞笑图集
搞笑试卷,学生恶搞答题
新闻热点
疑难解答
图片精选
从JSP 例子解析Web 安全编程实战
Jsp图片验证码实例代码
JSP如何统计在线人数和注册人数
java验证码
网友关注