Struts paging is an implementation! (two)

zhaozj2021-02-16  60

Query the code snippet of Action

public ActionForward execute (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {Base queryForm = (Base) form; if (!. queryForm.getName () equals ( "")) {PageController pc = new PageController () ; EmployeeBase service = new EmployeeBase (); ArrayList result = (ArrayList) service.search (queryForm, pc); HttpSession session = request.getSession (); session.setAttribute ( "queryForm", queryForm); session.setAttribute ( "pageController ", service.getPageController ()); request.setAttribute (" queryResult ", result); request.setAttribute (" pageController ", service.getPageController ()); return mapping.findForward (" haveResult ");} else {return mapping .forward ("noresult");}}

(3), page the code snippet

public ActionForward execute (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {file: // page read parameter TurnPageForm turnPageForm = (TurnPageForm) form; file: // PageController extracted from the query information, and bean call interface provides the processing result HttpSession session = request.getSession (); PageController pc = (PageController) session.getAttribute ( "pageController"); Base queryForm = (Base) session.getAttribute ( "queryForm"); pc.setCurrentPage (turnPageForm .getViewPage ()); EmployeeBase service = new EmployeeBase (); ArrayList result = (ArrayList) service.search (queryForm, pc); file: // parameter data write request request.removeAttribute ( "queryResult") according to; Request .removeAttribute ( "pageController"); request.setAttribute ( "queryResult", result); request.setAttribute ( "pageController", pc); file: // forward to the display page return mapping.findForward ( "haveResult");} ( 4) Database Access to the segment in Bean

Public Collection Search (Base Base, PageController PC) throws Sqlexception {ArrayList Emps = New ArrayList (); ResultSet RS = GetSearchResult (BASE);

rs.absolute (-1); pc.settotalrowsamount (Rs.Getrow ()); setPageController (PC); if (rs.getrow ()> 0) {

rs.absolute (pc.getpagestartrow ());

Do {system.out.println ("in loop" qGetrow ());

Base b = new base (); b.setname (rs.getstring ("name")); B.SetidCard (rs.getstring ("idcard")); System.out.Println ("from DB:" RS. GetString ("IDCARD")); Emps.Add (b); if (! rs.next ()) {Break;}} while (pc.getpagendrow () 1);} return Emps;}

(5) In JSP, the code snippet of the page section " class = "a02"> previous

Next

In this way, the functionality of the page can be expressed to the client in the way you like.

转载请注明原文地址:https://www.9cbs.com/read-22348.html

New Post(0)