我的struts分页算法的实现(2)

文章作者 100test 发表时间 2007:03:14 16:35:35
来源 100Test.Com百考试题网


在HTML中按下一页或者上一页的时候有如下代码:
nextPage

PreviousPage
然后在Action中作如下处理:
String currentPage = request.getParameter("currentPage").
HttpSession session = request.getSession().
EmployeeForm employeeForm = (EmployeeForm) form.
String queryString = null.
String queryCon = null.
String action = employeeForm.getAction().
List list = new ArrayList().
PageBean pb = null.
EmployeeDao employeeDao = new EmployeeDao().
if(action == null || action.equals("null")){
int totalRows = employeeDao.getTotalRows().

pb = new PageBean(totalRows).
session.removeAttribute("page").
queryString = employeeForm.getQueryString().
queryCon = employeeForm.getQueryCon().
session.setAttribute("queryString",queryString).
session.setAttribute("queryCon",queryCon).
list = employeeDao.getAllEmployee(queryString, queryCon,
String.valueOf(pb.getPageStartRow()),
String.valueOf(pb.getPageRecorders())).

}else if(action.equals("nextPage")){
queryString = (String)session.getAttribute("queryString").
queryCon = (String)session.getAttribute("queryCon").
employeeForm.setQueryString(queryString).
employeeForm.setQueryCon(queryCon).
pb = (PageBean)session.getAttribute("page").
pb.nextPage().
list = employeeDao.getAllEmployee(queryString, queryCon,
String.valueOf(pb.getPageStartRow()),
String.valueOf(pb.getPageRecorders())).
}else if(action.equals("previousPage")){
queryString = (String)session.getAttribute("queryString").
queryCon = (String)session.getAttribute("queryCon").
employeeForm.setQueryString(queryString).
employeeForm.setQueryCon(queryCon).
pb = (PageBean)session.getAttribute("page").
pb.previousPage().
list = employeeDao.getAllEmployee(queryString, queryCon,
String.valueOf(pb.getPageStartRow()),
String.valueOf(pb.getPageRecorders())).
}

pb.description().
session.setAttribute("page",pb).
request.setAttribute("admin", "admin").
request.setAttribute("employee", list).
return mapping.findForward("showlist").
然后在数据库查询中有如下代码:
/**
*查询总记录数
*/
public int getTotalRows() {

相关文章


Java开源项目Hibernate深度探险
JBuilderX SQLServer开发hibernate
我的struts分页算法的实现(2)
我的struts分页算法的实现(3)
我的struts分页算法的实现(1)
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛