JSP分页代码的深度解析

来源:爱站网时间:2018-09-27编辑:网友分享
今天小编给大家分享一篇JSP分页代码的深度解析,感兴趣的朋友跟小编一起来了解一下吧!

  今天小编给大家分享一篇JSP分页代码的深度解析,感兴趣的朋友跟小编一起来了解一下吧!

  有热心网友回复:

  str += " 转到

";

  for (int i = 1; i

  if (i == curPage)

  str += "

";

  else

  str += "

";

  }

  str += "

";

 

  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 mysql中文乱码的解决方法

下一篇:JSP中include指令和include动作有何不同?

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载