一个高效简洁的Struts分页方法 - 编程入门网
ctionForward execute (ActionMapping mapping, Actionform form,
HttpServletRequest request,
HttpServletResponse response)
{
ActionForward myforward = null ;
String myaction = mapping.getParameter () ;
if (isCancelled (request))
{
return mapping.findForward ("failure") ;
}
if ("".equalsIgnoreCase (myaction))
{
myforward = mapping.findForward ("failure") ;
}
else if ("LIST".equalsIgnoreCase (myaction))
{
myforward = performList (mapping, form, request, response) ;
}
else
{
myforward = mapping.findForward ("failure") ;
}
return myforward ;
}
private ActionForward performList (ActionMapping mapping,
Actionform actionform,
HttpServletRequest request,
HttpServletResponse response)
{
try
{
DataSource ds = (DataSource) servlet.getServletContext().getAttribute(Action.DATA_SOURCE_KEY);
CertificateDAO certificateDAO = new CertificateDAO (ds) ;
int offset = 0; //翻页时的起始记录所在游标
int length = PAGE_LENGTH;
String pageOffset = request.getParameter("pager.offset");
if (pageOffset == null || pageOffset.equals("")) {
offset = 0;
} else {
offset = Integer.parseInt(pageOffset);
}
List certificateList = certificateDAO .findCertificateList (offset,length) ;
int size = certificateDAO.getRows(); // 取得总记录数
String url = request.getContextPath()+"/"+mapping.getPath()+".do";
String pagerHeader = Pager.generate(offset, size, length, url); //分页处理
request.setAttribute ("pager", pagerHeader) ;
request.setAttribute ("list", certificateList) ;
}
catch (Exception e)
{
e.printStackTrace();
return mapping.findForward ("error") ;
}
return mapping.findForward ("success") ;
}
}
CertificateAction.java主要是把数据从DAO中取出,并放入一个ArrayList 中,然后通过配置文件再软件View的JSP页。 一个高效简洁的Struts分页方法(4)时间:2011-03-205、建立视图listcertificate.jsp文件。 jsp代码: 代码:
|
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |