jsp標籤分頁+Flex HttpServer

來源:互聯網
上載者:User

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標籤分頁代碼

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><%@include file="../TagLib/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><!--============要先取得參數sessionScope.currentPage之後在做sql,順序相反的話sql需要的條件沒有更新取得的資料是根據上一次參數取得的舊資料======================================================  --><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="${pageSize}">SELECT * from emp,position where emp.emp_position=position.position_id;</sql:query><!--第一次查詢後就應該儲存totalPage在session中這樣後面param.pageTo=='last'的時候可以在session中擷取總頁數--><fmt:formatNumber var="formatPage"value="${selectEmpAll.rowCount/pageSize}" type="number" pattern="#"/><!--格式化之後的總頁數會被四捨五入所以要下面的判斷避免2.1頁四捨五入為2頁--><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><!-- 將非可視元素(例如服務、值對象)放在此處 --><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;[Bindable]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,"錯誤提示"); }protected function empDataGrid_doubleClickHandler(event:MouseEvent):void{var empEo:EmpEO=new EmpEO;  var empDetail:EmpDetail=EmpDetail(PopUpManager.createPopUp(this,EmpDetail,true));/* ================詳細資料按鈕要調用這個函數所以不能用(event.currentTarget as DataGrid)==按鈕的currentTarget是按鈕本身不是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.selectedItem.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.selectedItem.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="共"+employeesList.getItemAt(0).totalPage+"頁";currentPage.text="第"+employeesList.getItemAt(0).currentPage+"頁";option.text=employeesList.getItemAt(0).pageTo as String;}protected function paginationBt_clickHandler(event:MouseEvent):void{switch(event.target.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 requestUtil:RequestUtil=new RequestUtil;requestUtil.doPostRequest(url, params, requestResult);} *//* private function requestResult(event:Event){var loader:URLLoader = URLLoader(event.target); employeesList=loader.data as ArrayCollection;}  */protected function module_creationCompleteHandler(event:FlexEvent):void{getAllEmp.send();}protected function addBtn_clickHandler(event:MouseEvent):void{PopUpManager.createPopUp(this,AddEmp,true);}]]></fx:Script><s:Button x="518" bottom="10" label="詳細" click="empDataGrid_doubleClickHandler(event)"/><s:Button id="addBtn" x="50" y="10" label="添加" click="addBtn_clickHandler(event)"/><s:Button id="lastBt" x="271" bottom="10" label="尾頁" click="paginationBt_clickHandler(event)"/><s:Button id="nextBt" x="199" bottom="10" label="下一頁" click="paginationBt_clickHandler(event)"/><s:Button id="preBt" x="127" bottom="10" label="上一頁" click="paginationBt_clickHandler(event)"/><s:Button id="firstBt" x="55" bottom="10" label="首頁" click="paginationBt_clickHandler(event)"/><s:Label id="totalPage" x="371" y="368" text="共幾頁"/><s:Label id="currentPage" x="412" y="368" text="第幾頁"/><s:Label id="option" x="458" y="368" text="向前"/><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="員工號"></s:GridColumn><s:GridColumn dataField="emp_id" headerText="社會安全號碼"></s:GridColumn><s:GridColumn dataField="emp_name" headerText="名稱"></s:GridColumn><s:GridColumn dataField="emp_sex" headerText="性別"></s:GridColumn><s:GridColumn dataField="dept_name" headerText="部門"></s:GridColumn><s:GridColumn dataField="position_name" headerText="職位"></s:GridColumn><!--<s:GridColumn dataField="emp_address" headerText="住址"></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="手機號"></s:GridColumn><s:GridColumn dataField="emp_email" headerText="email"></s:GridColumn><s:GridColumn dataField="emp_sal" headerText="薪水"></s:GridColumn><s:GridColumn dataField="emp_bank_account" headerText="銀行帳號"></s:GridColumn><s:GridColumn dataField="emp_birthday" headerText="生日"></s:GridColumn>--></s:ArrayList></s:columns></s:DataGrid></s:Module>

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.