Taglib. jsp
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %><%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %><%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %><%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %><%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
JSP tag paging code
<% @ Page Language = "Java" contenttype = "text/html; charset = UTF-8" pageencoding = "UTF-8" %> <% @ include file = ".. /taglib. JSP "%> <C: If test =" $ {sessionscope. currentpage = NULL} "> <C: Set Var =" currentpage "value =" 1 "Scope =" session "/> <C: out value = "init"> </C: Out> </C: If> <C: Set Var = "pagesize" value = "15"> </C: set> <C: If test = "$ {Param. pagesize! = NULL} "> <C: Set Var =" pagesize "value =" $ {Param. pagesize} "> </C: Set> </C: If> <C: Choose> <C: When test =" $ {Param. pageto = 'first'} "> <C: Set Var =" currentpage "value =" 1 "Scope =" session "/> </C: When> <C: when test = "$ {Param. pageto = 'pre'} "> <C: Set Var =" currentpage "value =" $ {(sessionscope. currentpage = 1 )? 1: sessionscope. currentPage-1} "Scope =" session "/> </C: When> <C: When test =" $ {Param. pageto = 'Next'} "> <C: Set Var =" currentpage "value =" $ {(sessionscope. currentpage = totalpage )? Totalpage: sessionscope. currentpage + 1} "Scope =" session "/> </C: When> <C: When test =" $ {Param. pageto = 'last'} "> <C: Set Var =" currentpage "value =" $ {sessionscope. totalpage} "Scope =" session "/> </C: When> </C: Choose> <! -- ============== You must first obtain the sessionscope parameter. SQL statement after currentpage, if the order is the opposite, the SQL requires that the condition is not updated. The obtained data is obtained based on the old data obtained in the previous parameter ================== ============================================================= --> <SQL: setdatasource driver = "com. mySQL. JDBC. driver "url =" JDBC: mysql: // localhost: 3306/hrmanager? Autoreconnect = true & useunicode = true & characterencoding = utf8 "user =" root "Password =" hgs3721102 "Scope =" application "Var =" datasource "/> <SQL: query Var = "selectempall" datasource = "$ {datasource}"> select * from EMP, position where EMP. emp_position = position. position_id; </SQL: Query> <SQL: Query Var = "selectemppagination" datasource = "$ {datasource}" startrow = "$ {(sessionscope. currentPage-1) * pagesize} "maxrows =" $ {pages Ize} "> select * from EMP, position where EMP. emp_position = position. position_id; </SQL: Query> <! -- After the first query, the totalpage should be saved in the session. when pageto = 'last', you can obtain the total number of pages in the session --> <FMT: formatnumber Var = "formatpage" value = "$ {selectempall. rowcount/pagesize} "type =" Number "pattern =" # "/> <! -- The total number of formatted pages is rounded down. Therefore, the following judgment should be taken to avoid rounding 2.1 pages to 2 pages --> <C: If test = "$ {formatpage * pagesize> = selectempall. rowcount} "> <C: Set Var =" totalpage "value =" $ {formatpage} "Scope =" session "> </C: Set> </C: if> <C: If test = "$ {formatpage * pagesize <selectempall. rowcount} "> <C: Set Var =" totalpage "value =" $ {formatpage + 1} "Scope =" session "> </C: Set> </C: if> <? XML version = "1.0" encoding = "UTF-8"?> <EMPs> <C: foreach Var = "empeo" items = "$ {selectemppagination. rows} "> <EMP> <pageto> <C: Out value =" $ {Param. pageto} "/> </pageto> <currentpage> <C: Out value =" $ {sessionscope. currentpage} "/> </currentpage> <totalpage> <C: Out value =" $ {totalpage} "/> </totalpage> <emp_address> <C: out value = "$ {empeo. emp_address} "/> </emp_address> <emp_bank_account> <C: Out value =" $ {empeo. emp_bank_account} "/> </emp_bank_account> <emp_birth_place> <C: Out value =" $ {empeo. emp_birth_place} "/> </emp_birth_place> <emp_birthday> <C: Out value =" $ {empeo. emp_birthday} "/> </emp_birthday> <emp_dept> <C: Out value =" $ {empeo. emp_dept} "/> </emp_dept> <emp_education> <C: Out value =" $ {empeo. emp_education} "/> </emp_education> <emp_email> <C: Out value =" $ {empeo. emp_email} "/> </emp_email> <emp_id> <C: Out value =" $ {empeo. emp_id} "/> </emp_id> <emp_name> <C: Out value =" $ {empeo. emp_name} "/> </emp_name> <emp_no> <C: Out value =" $ {empeo. emp_no} "/> </emp_no> <emp_password> <C: Out value =" $ {empeo. emp_password} "/> </emp_password> <emp_photo> <C: Out value =" $ {empeo. emp_photo} "/> </emp_photo> <emp_position> <C: Out value =" $ {empeo. emp_position} "/> </emp_position> <emp_sal> <C: Out value =" $ {empeo. emp_sal} "/> </emp_sal> <emp_school> <C: Out value =" $ {empeo. emp_school} "/> </emp_school> <emp_service_year> <C: Out value =" $ {empeo. emp_service_year} "/> </emp_service_year> <emp_sex> <C: Out value =" $ {empeo. emp_sex} "/> </emp_sex> <emp_status> <C: Out value =" $ {empeo. emp_status} "/> </emp_status> <emp_telphone> <C: Out value =" $ {empeo. emp_telphone} "/> </emp_telphone> <dept_name> <C: Out value =" $ {empeo. dept_name} "/> </dept_name> <position_name> <C: Out value =" $ {empeo. position_name} "/> </position_name> </EMP> </C: foreach> </EMPs>
Flex httpservice
<? XML version = "1.0" encoding = "UTF-8"?> <S: module xmlns: FX = "http://ns.adobe.com/mxml/2009" xmlns: S = "Library: // ns.adobe.com/flex/spark" xmlns: MX = "Library: // ns.adobe.com/flex/mx "width =" 800 "Height =" 400 "creationcomplete =" module_creationcompletehandler (event) "> <FX: style source =" assets/mycss.css "/> <FX: declarations> <! -- Place non-visual elements (such as services and value objects) Here --> <s: httpservice id = "getallemp" fault = "getallemp_faulthandler (Event) "method =" Post "showbusycursor =" true "result =" getallemp_resulthandler (event) "url =" http: // localhost: 8080/hrmanagerserver/empmanage/pagination. JSP "useproxy =" false "> <s: Request xmlns =" "> <pageto >{pageto} </pageto> <! -- <Temp> {math. random ()} </temp> --> <pagesize> {pagesize} </pagesize> </S: Request> </S: httpservice> </FX: declarations> <FX: SCRIPT> <! [CDATA [import EO. empeo; import util. requestutil; import component. empdetail; import component. addemp; import MX. collections. arraycollection; import MX. collections. xmllistcollection; import MX. controls. alert; import MX. controls. datefield; import MX. events. flexevent; import MX. managers. popupmanager; import MX. RPC. events. faultevent; import MX. RPC. events. resultevent; import spark. events. gridselectionevent; [bindabl E] private var employeeslist: arraycollection; [Bindable] private var pagesize: Number = 10; [Bindable] private var pageto: String = "first"; protected function getallemp_faulthandler (Event: faultevent): void {alert. show (event. fault. faultstring, "error prompt");} protected function failed (Event: mouseevent): void {var empeo: empeo = new empeo; var empdetail: empdetail = empdetail (popupmanager. createpopup (T His, empdetail, true);/* ===================== the detailed information button to call this function, so it cannot be used (event. currenttarget as DataGrid) = The currenttarget of the button is that the button itself is not a datagriditem ========================== ================= */empeo. emp_address = empdatagrid. selecteditem. emp_address; empeo. emp_bank_account = empdatagrid. selecteditem. emp_bank_account; empeo. emp_birth_place = empdatagrid. selecteditem. emp_birth_place; var birthdaystring: String = empdatagrid. sele Cteditem. emp_birthdayempeo.emp_birthday = datefield. stringtodate (birthdaystring, "YYYY-MM-DD"); empeo. emp_dept = empdatagrid. selecteditem. emp_dept as number; empeo. emp_education = empdatagrid. selecteditem. emp_education; empeo. emp_email = empdatagrid. selecteditem. emp_email; empeo. emp_id = empdatagrid. selecteditem. emp_id; empeo. emp_name = empdatagrid. selecteditem. emp_name; empeo. emp_no = empdatagrid. selecteditem. emp_no As number; empeo. emp_password = empdatagrid. selecteditem. emp_password; empeo. emp_photo = empdatagrid. selecteditem. emp_photo; empeo. emp_position = empdatagrid. selecteditem. emp_position as number; empeo. emp_sal = empdatagrid. selecteditem. emp_sal as number; empeo. emp_school = empdatagrid. selecteditem. emp_school; empeo. emp_service_year = empdatagrid. selecteditem. emp_service_year as number; empeo. emp_sex = empdatagrid. sele Cteditem. emp_sex; empeo. emp_status = empdatagrid. selecteditem. emp_status; empeo. emp_telphone = empdatagrid. selecteditem. emp_telphone; empeo. dept_name = empdatagrid. selecteditem. dept_name; empeo. position_name = empdatagrid. selecteditem. position_name; empdetail. EMP = empeo;} protected function getallemp_resulthandler (Event: resultevent): void {employeeslist = event. result. EMPs. EMP; totalpage. TEXT = "Total" + employeeslist. geti Temat (0 ). totalpage + "page"; currentpage. TEXT = "" + employeeslist. getitemat (0 ). currentpage + "page"; option. TEXT = employeeslist. getitemat (0 ). pageto as string;} protected function paginationbt_clickhandler (Event: mouseevent): void1_switch(event.tar get. id. charat (0) {Case 'l': {pageto = "last"; getallemp. send (); // sendhttprequest ("last"); break;} case 'N': {pageto = "Next"; getallemp. send (); // sendhttprequest ("Next"); break;} case' P': {pageto = "pre"; getallemp. send (); // sendhttprequest ("pre"); break;} case 'F': {pageto = "first"; getallemp. send (); // sendhttprequest ("first"); break ;}}/ * Private function sendhttprequest (pageto: string): void {var URL: String = "http: // localhost: 8080/hrmanagerserver/empmanage/pagination2.jsp "; var Params: urlvariables = new urlvariables (" temp = "+ math. random (); Params. pageto = pageto; Params. pagesize = pagesize; var req Uestutil: requestutil = new requestutil; requestutil. dopostrequest (URL, Params, requestresult);} * // * Private function requestresult (Event: Event) {var Loader: urlloader = urlloader(event.tar get); employeeslist = loader. data as arraycollection;} */protected function module_creationcompletehandler (Event: flexevent): void {getallemp. send ();} protected function addbtn_clickhandler (Event: mouseevent): void {popupmana Ger. createpopup (this, addemp, true);}]> </FX: SCRIPT> <s: button x = "518" Bottom = "10" label = "details" Click = "empdatagrid_doubleclickhandler (event)"/> <s: button id = "addbtn" x = "50" Y = "10" label = "add" Click = "addbtn_clickhandler (event)"/> <s: button id = "lastbt" x = "271" Bottom = "10" label = "last page" Click = "paginationbt_clickhandler (event)"/> <s: button id = "nextbt" x = "199" Bottom = "10" label = "next page" Click = "paginationbt_clickhandl Er (event) "/> <s: button id =" prebt "x =" 127 "Bottom =" 10 "label =" Previous Page "Click =" paginationbt_clickhandler (Event) "/> <s: button id =" firstbt "x =" 55 "Bottom =" 10 "label =" Homepage "Click =" paginationbt_clickhandler (event) "/> <s: label id = "totalpage" x = "371" Y = "368" text = "Total pages"/> <s: label id = "currentpage" x = "412" Y = "368" text = "page number"/> <s: label id = "option" x = "458" Y = "368" text = "Forward"/> <s: DataGrid id = "empdatagrid" Top = "50" width =" "700" Height = "300" dataprovider = "{employeeslist}" DoubleClick = "empdatagrid_doubleclickhandler (Event) "doubleclickenabled =" true "horizontalcenter =" 0 "requestedrowcount =" 4 "> <s: columns> <s: arraylist> <s: gridcolumn datafield = "emp_no" headertext = "employee ID"> </S: gridcolumn> <s: gridcolumn datafield = "emp_id" headertext = "ID card number"> </s: gridcolumn> <s: gridcolumn datafield = "emp_name" headertext = "name"> </S: gridcolumn> <s: gridcolu Mn datafield = "emp_sex" headertext = "gender"> </S: gridcolumn> <s: gridcolumn datafield = "dept_name" headertext = "department"> </s: gridcolumn> <s: gridcolumn datafield = "position_name" headertext = ""> </S: gridcolumn> <! -- <S: gridcolumn datafield = "emp_address" headertext = "Address"> </S: gridcolumn> <s: gridcolumn datafield = "emp_birth_place" headertext = ""> </S: gridcolumn> <s: gridcolumn datafield = "emp_education" headertext = ""> </s: gridcolumn> <s: gridcolumn datafield = "emp_telphone" headertext = "mobile phone number"> </S: gridcolumn> <s: gridcolumn datafield = "emp_email" headertext = "email"> </S: gridcolumn> <s: gridcolumn datafield = "emp_sal" headertext = "salary"> </s: gridcolumn> <s: gridcolumn datafield = "emp_bank_account" headertext = "bank account"> </S: gridcolumn> <s: gridcolumn datafield = "emp_birthday" headertext = "Birthday"> </S: gridcolumn> --> </S: arraylist> </S: columns> </s: dataGrid> </S: module>