jsp页面 列表 展示 ajax异步实现方法
1.服务端先返回页面基本结构(如message.jsp),
<%@pagelanguage="java"contentType="text/html;charset=utf-8" pageEncoding="utf-8"%> <%@taglibprefix="c"uri="http://java.sun.com/jsp/jstl/core"%> <%@taglibprefix="fmt"uri="http://java.sun.com/jsp/jstl/fmt"%> <% Stringpath=request.getContextPath(); StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort() +path+"/"; %> <!DOCTYPEhtml> <!--[ifltIE7]><htmlclass="ieie6lt-ie9lt-ie8lt-ie7"lang="en"><![endif]--> <!--[ifIE7]><htmlclass="ieie7lt-ie9lt-ie8"lang="en"><![endif]--> <!--[ifIE8]><htmlclass="ieie8lt-ie9"lang="en"><![endif]--> <!--[ifIE9]><htmlclass="ieie9"lang="en"><![endif]--> <!--[if!IE]><!--> <htmllang="en"class="no-ie"> <!--<![endif]--> <head> <!--Meta--> <metacharset="utf-8"> <metaname="viewport"content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0"> <metaname="description"content=""> <metaname="keywords"content=""> <metaname="author"content=""> <title>消息中心</title> <!--HTML5shimandRespond.jsIE8supportofHTML5elementsandmediaqueries--> <!--[ifltIE9]><scriptsrc="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script><scriptsrc="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script><![endif]--> <!--BootstrapCSS--> <linkrel="stylesheet"href="<%=path%>/app/css/bootstrap.css"> <!--VendorCSS--> <linkrel="stylesheet"href="<%=path%>/vendor/fontawesome/css/font-awesome.min.css"> <linkrel="stylesheet"href="<%=path%>/vendor/animo/animate+animo.css"> <!--STARTPageCustomCSS--> <!--DataTablestyles--> <linkrel="stylesheet"href="<%=path%>/vendor/datatable/extensions/datatable-bootstrap/css/dataTables.bootstrap.css"> <linkrel="stylesheet"href="<%=path%>/vendor/datatable/extensions/ColVis/css/dataTables.colVis.css"> <!--ENDPageCustomCSS--> <!--AppCSS--> <linkrel="stylesheet"href="<%=path%>/app/css/app.css"> <linkrel="stylesheet"href="<%=path%>/app/css/beadmin-theme-c2.css"> <linkrel="stylesheet"href="<%=path%>/vendor/sweetalert/lib/sweet-alert.css"/> <linkrel="stylesheet"href="<%=path%>/css/page.css"/> <!--ModernizrJSScript--> <scriptsrc="<%=path%>/vendor/modernizr/modernizr.js"type="application/javascript"></script> <!--FastClickformobiles--> <scriptsrc="<%=path%>/vendor/fastclick/fastclick.js"type="application/javascript"></script>. <script> varbasePath='<%=basePath%>'; varpageNo=${page.pageNo}; vartotalCount=${page.totalCount}; vartotalPage=${page>totalPage}; varpageSize=${page.pageSize}; </script> </head> <body> <!--STARTMainwrapper--> <divclass="wrapper"> <!--STARTMainsection--> <section> <!--STARTPagecontent--> <divclass="content-wrapper"style="margin-left:-250px;margin-top:-40px;"> <h3>消息中心 <!--<divstyle="float:right;margin-top:5px;"class="form-group"> <buttontype="button"onclick="$('#myModal').modal({backdrop:'static',keyboard:false});;"class="btnbtn-labeledbtn-success"><spanclass="btn-label"><iclass="fafa-plus"></i></span>添加</button> </div>--> <small>消息管理</small> </h3> <!--STARTpanel--> <!--STARTDATATABLE3--> <divclass="row"> <divclass="col-lg-12"> <divclass="panelpanel-default"> <divclass="panel-heading"style="border-bottom:1pxsolid#eee;"> <formclass="form-inline"id="searchForm"method="post"action="<%=path%>/page/messageSearch.action"> <divclass="form-group"><b>创建时间: </b> <divclass="datetimepickerinput-groupdatemb-lg"data-pick-time="false"> <inputtype="text"class="form-control"id="searchDateStart"name="searchDateStart"value=''disabled="disabled"> <spanclass="input-group-addon"><spanclass="fa-calendarfa"></span></span></div> <spanstyle="margin-top:-8px;">—</span> <divclass="datetimepickerinput-groupdatemb-lg"data-pick-time="false"> <inputtype="text"class="form-control"id="searchDateEnd"name="searchDateEnd"value=''disabled="disabled"> <spanclass="input-group-addon"><spanclass="fa-calendarfa"></span></span></div> </div> <divclass="form-group"> <b>接收者: </b> <inputtype="text"class="form-controlmb-lg"id="receiver"name="receiver"value=''> </div> <divclass="form-group"><astyle="margin:-10px005px;float:left;"href="javascript:void(0);"class="mb-smbtnbtn-primary"type="button"id="searchMessage">搜索</a></div> <inputtype="hidden"id="pageNo"name="pageNo"value=''> </form> </div> <divclass="table-responsive"> <tableclass="tabletable-borderedtable-hoverdataTableno-footer"id="table-ext-1"> <thead> <tr> <thstyle="width:300px;">描述</th> <thclass="sortingcenter"tabindex="0"aria-controls="datatable1"rowspan="1"colspan="1"style="width:86px;"aria-label="Renderingengine:activatetosortcolumnascending">发送者</th> <thclass="sortingcenter"tabindex="0"aria-controls="datatable1"rowspan="1"colspan="1"style="width:86px;"aria-label="Renderingengine:activatetosortcolumnascending">接收者</th> <thclass="sortingcenter"tabindex="0"aria-controls="datatable1"rowspan="1"colspan="1"style="width:86px;"aria-label="Renderingengine:activatetosortcolumnascending">创建时间</th> <thclass="th150center">操作</th> </tr> </thead> <tbodyid="message_body"> </tbody> <tfoot> <tr></tr> </tfoot> </table> </div> <divclass="panel-footer"> <divclass="row"> <divstyle="line-height:35px;"class="col-lg-3"> <divclass="input-grouppull-left"id="message_showLines"></div> </div> <divclass="col-lg-9"></div> <divclass="tcdPageCode"></div> </div> </div> </div> </div> </div> <!--ENDDATATABLE3--> </div> <!--ENDPagecontent--> </section> <!--ENDMainsection--> </div> <!--ENDMainwrapper--> <!--STARTmodal--> <divid="myModal"tabindex="-1"role="dialog"aria-labelledby="myModalLabel"aria-hidden="true"class="modal"> <divclass="modal-dialog"style="width:600px;"> <divclass="modal-content"> <divclass="modal-header"> <buttontype="button"data-dismiss="modal"aria-hidden="true"class="close">×</button> <h4id="myModalLabel"class="modal-title">新建应用</h4> </div> <divclass="modal-body"style="padding-right:20px;"> <formmethod="get"action="/"class="form-horizontal"> <fieldset> <divclass="form-group"style="padding-bottom:5px;"> <labelclass="col-sm-2control-label">名称</label> <divclass="col-sm-10"> <inputtype="text"class="form-control"> </div> </div> <divclass="form-group"style="margin-top:10px;"> <labelclass="col-sm-2control-label">描述</label> <divclass="col-sm-10"> <inputtype="text"class="form-control"> </div> </div> <divclass="form-group"style="margin-top:10px;"> <labelclass="col-sm-2control-label">URL</label> <divclass="col-sm-10"> <inputtype="text"class="form-control"> </div> </div> <divclass="form-group"style="margin-top:5px;"> <labelclass="col-sm-2control-label">类别</label> <divclass="col-sm-10"> <selectclass="form-controlm-b"name="account"> <option>Web</option> <option>Mobile</option> </select></div> </div> <divclass="form-group"style="margin-top:5px;"> <labelclass="col-sm-2control-label">授权模式</label> <divclass="col-sm-10"> <selectclass="form-controlm-b"name="account"> <option>授权</option> <option>不授权</option> </select></div> </div> <divclass="form-group"style="margin-top:10px;"> <labelclass="col-sm-2control-label">LOGO</label> <divclass="col-sm-10"> <inputtype="button"class="form-control"> </div> </div> </fieldset> </form> </div> </fieldset> <divclass="modal-footer"> <buttontype="button"data-dismiss="modal"class="btnbtn-default">取消</button> <buttontype="button"class="btnbtn-primary">确定</button> </div> </div> </div> </div> </div> <divid="myModal2"tabindex="-1"role="dialog"aria-labelledby="myModalLabel"aria-hidden="true"class="modal"> <divclass="modal-dialog"style="width:650px;"> <divclass="modal-content"> <divclass="modal-header"> <buttontype="button"data-dismiss="modal"aria-hidden="true"class="close">×</button> <h4id="myModalLabel"class="modal-title">修改密码</h4> </div> <divclass="modal-body"> <formmethod="get"action="/"class="form-horizontal"> <fieldset> <divclass="form-group"style="padding-bottom:5px;"> <labelclass="col-sm-2control-label">原密码</label> <divclass="col-sm-10"> <inputtype="text"class="form-control"> </div> </div> <divclass="form-group"style="padding-bottom:5px;"> <labelclass="col-sm-2control-label">新密码</label> <divclass="col-sm-10"> <inputtype="password"name="password"class="form-control"> </div> </div> <divclass="form-group"style="padding-bottom:5px;"> <labelclass="col-sm-2control-label">确认密码</label> <divclass="col-sm-10"> <inputtype="password"name="password"class="form-control"> </div> </div> </fieldset> </form> </div> <divclass="modal-footer"> <buttontype="button"data-dismiss="modal"class="btnbtn-default">关闭</button> <buttontype="button"class="btnbtn-primary">Savechanges</button> </div> </div> </div> </div> <divid="myModal3"tabindex="-1"role="dialog"aria-labelledby="myModalLabel"aria-hidden="true"class="modal"> <divclass="modal-dialog"style="width:600px;"> <divclass="modal-content"> <divclass="modal-header"> <buttontype="button"data-dismiss="modal"aria-hidden="true"class="close">×</button> <h4id="myModalLabel"class="modal-title">编辑节目特殊单</h4> </div> <divclass="modal-body"> <formmethod="get"action="/"class="form-horizontal"> <fieldset> <divclass="form-group"style="padding-bottom:5px;"> <labelclass="col-sm-2control-label">表单标题</label> <divclass="col-sm-10"> <inputtype="text"class="form-control"> </div> </div> </fieldset> </form> </div> <divclass="modal-footer"> <buttontype="button"data-dismiss="modal"class="btnbtn-default">关闭</button> <buttontype="button"class="btnbtn-primary">确定</button> </div> </div> </div> </div> <!--ENDmodal--> <formmethod="post"id="pageForm"name="pageForm" action="<%=path%>/page/message_search.action"> <inputtype="hidden"id="pageNo"name="pageNo"value=""/> </form> <!--STARTScripts--> <!--MainvendorScripts--> <scriptsrc="<%=path%>/vendor/jquery/jquery.min.js"></script> <scriptsrc="<%=path%>/vendor/bootstrap/js/bootstrap.min.js"></script> <!--Plugins--> <scriptsrc="<%=path%>/vendor/chosen/chosen.jquery.min.js"></script> <scriptsrc="<%=path%>/vendor/slider/js/bootstrap-slider.js"></script> <scriptsrc="<%=path%>/vendor/filestyle/bootstrap-filestyle.min.js"></script> <!--Animo--> <scriptsrc="<%=path%>/vendor/animo/animo.min.js"></script> <!--Sparklines--> <scriptsrc="<%=path%>/vendor/sparklines/jquery.sparkline.min.js"></script> <!--MomentJsandDatepicker--> <scriptsrc="<%=path%>/vendor/moment/min/moment-with-langs.js"></script> <scriptsrc="<%=path%>/vendor/datetimepicker/js/bootstrap-datetimepicker.min.js"></script> <!--Slimscroll--> <scriptsrc="<%=path%>/vendor/slimscroll/jquery.slimscroll.min.js"></script> <!--Store+JSON--> <scriptsrc="<%=path%>/vendor/store/store+json2.min.js"></script> <!--ScreenFull--> <scriptsrc="<%=path%>/vendor/screenfull/screenfull.min.js"></script> <!--STARTPageCustomScript--> <!--DataTableScripts--> <scriptsrc="<%=path%>/vendor/datatable/media/js/jquery.dataTables.min.js"></script> <scriptsrc="<%=path%>/vendor/datatable/extensions/datatable-bootstrap/js/dataTables.bootstrap.js"></script> <scriptsrc="<%=path%>/vendor/datatable/extensions/datatable-bootstrap/js/dataTables.bootstrapPagination.js"></script> <scriptsrc="<%=path%>/vendor/datatable/extensions/ColVis/js/dataTables.colVis.min.js"></script> <!--STARTPageCustomScript--> <scriptsrc="<%=path%>/vendor/wizard/js/bwizard.min.js"></script> <!--FormValidation--> <scriptsrc="<%=path%>/vendor/parsley/parsley.min.js"></script> <!--ENDPageCustomScript--> <!--AppMain--> <scriptsrc="<%=path%>/app/js/app.js"></script> <scriptsrc="<%=path%>/vendor/sweetalert/lib/sweet-alert.min.js"></script> <scriptsrc="<%=path%>/script/message.js"></script> <scriptsrc="<%=path%>/page/js/page.js"></script> <!--ENDScripts--> </body> </html>
2.example.js加载的时候,再去异步请求获取页面数据(表格、分页等),再动态创建表,分页链接等
$(function(){ initTable(); $("#searchMessage").on("click",function(){ messageSearch(pageNo); }); //获取message列表"pageNo":pageNo functioninitTable(){ $.ajax({ url:basePath+"page/message_list.action", type:"get", dataType:"json", success:function(dataMap){ createTBody(dataMap); createTFoot(dataMap); }, error:function(errorData){ } }); } //查询message functionmessageSearch(pageNo){ varsearchDateStart=$("#searchDateStart").val(); varsearchDateEnd=$("#searchDateEnd").val(); varstartDate=newDate(searchDateStart); varendDate=newDate(searchDateEnd); varnum=endDate-startDate; if(num<0){ $("#searchDateEnd").val(''); swal({ title:"结束日期不能晚于开始日期", text:"", type:"error" }); returnfalse; } varreceiver=$("#receiver").val(); $.ajax({ url:basePath+"page/message_search.action", type:"POST", data:{ "pageNo":pageNo, "searchDateStart":searchDateStart, "searchDateEnd":searchDateEnd, "receiver":receiver }, dataType:"json", success:function(dataMap){ createTBody(dataMap); createTFoot(dataMap); }, error:function(errorData){ } }); } functioncreateTBody(dataMap){ if(dataMap!=null){ varmessageListPage=dataMap.messageListPage; varhtml=[]; for(vari=0;i<messageListPage.length;i++){ varmessage=messageListPage[i]; varcTime=message.createtime.replace(/T/g,""); html.push('<trclass="gradeXcenter">'); html.push('<tdstyle="text-align:left;">'+message.content+'</td>'); html.push('<td>'+message.provider+'</td>'); html.push('<td>'+message.receiver+'</td>'); html.push('<td>'+cTime+'</td>'); html.push('<tdmessage_id='+message.id+'><ahref="#"class="message_delbtnbtn-dangerbtn-xs"> 删除 </a></td>'); html.push('</tr>'); } $("#message_body").empty().html(html.join('')); } } functioncreateTFoot(dataMap){ if(dataMap!=null){ startNum=dataMap.startNum; stopNum=dataMap.stopNum; totalCount=dataMap.totalCount; pageNo=dataMap.pageNo; pageSize=dataMap.pageSize; varstr='显示'+startNum+'至'+stopNum+'项,共'+totalCount+'项。'; $("#message_showLines").html(str); } } $('#message_body').on('click','a.message_del',function(){ varmessage_id=$(this).parent("td").attr("message_id"); swal({ title:"确认要删除吗?", text:"删除后将不能恢复!", type:"warning", showCancelButton:true, confirmButtonColor:"#DD6B55", confirmButtonText:"Yes,deleteit!", cancelButtonText:"No,cancelplx!", closeOnConfirm:false, closeOnCancel:false },function(isConfirm){ if(isConfirm){ $.ajax({ url:basePath+"page/message_del.action", data:{ "id":message_id }, type:"get", dataType:"json", success:function(dataMap){ if(dataMap!=null&&dataMap.message=="success"){ swal("删除!", "已经成功删除.", "success"); initTable(); }else{ swal("删除!", "删除失败.", "error"); } }, error:function(errorMsg){ swal("删除失败!", errorMsg, "error"); } }); }else{ swal("Cancelled","Yourimaginaryfileissafe:)", "error"); } }); }); $('.tcdPageCode').extendPagination({ pageId:pageNo, totalCount:totalCount, showPage:5, limit:pageSize, callback:function(pageNo,limit,totalCount){ messageSearch(pageNo); } }); });
注意:表格是动态创建的,其中的按钮绑定事件时,一定要先找到它的父节点(或祖先节点),再到指定节点,绑定事件
如上面的 $("#serviceRepo_body").on('click','a.record_view',function(){});
分页js插件(page.js),同时引入jquery-1.11.1.min.js和bootstrap.js
/** *CreatedbyHopeon2014/12/28. */ (function($){ $.fn.extendPagination=function(options){ vardefaults={ pageId:'', totalCount:'', showPage:'10', limit:'5', callback:function(){ returnfalse; } }; $.extend(defaults,options||{}); //alert(defaults.pageId); if(defaults.totalCount==''){ //alert('总数不能为空!'); $(this).empty(); returnfalse; }elseif(Number(defaults.totalCount)<=0){ //alert('总数要大于0!'); $(this).empty(); returnfalse; } if(defaults.showPage==''){ defaults.showPage='10'; }elseif(Number(defaults.showPage)<=0)defaults.showPage='10'; if(defaults.limit==''){ defaults.limit='5'; }elseif(Number(defaults.limit)<=0)defaults.limit='5'; vartotalCount=Number(defaults.totalCount),showPage=Number(defaults.showPage), limit=Number(defaults.limit),totalPage=Math.ceil(totalCount/limit); if(totalPage>0){ varhtml=[]; html.push('<ulclass="pagination">'); html.push('<liclass="previous"><ahref="#">«</a></li>'); html.push('<liclass="disabledhidden"><ahref="#">...</a></li>'); if(totalPage<=showPage){ for(vari=1;i<=totalPage;i++){ if(i==defaults.pageId)html.push('<liclass="active"><ahref="#">'+i+'</a></li>'); elsehtml.push('<li><ahref="#">'+i+'</a></li>'); } }else{ for(varj=1;j<=showPage;j++){ if(j==defaults.pageId)html.push('<liclass="active"><ahref="#">'+j+'</a></li>'); elsehtml.push('<li><ahref="#">'+j+'</a></li>'); } } html.push('<liclass="disabledhidden"><ahref="#">...</a></li>'); html.push('<liclass="next"><ahref="#">»</a></li></ul>'); $(this).html(html.join('')); if(totalPage>showPage)$(this).find('ul.paginationli.next').prev().removeClass('hidden'); varpageObj=$(this).find('ul.pagination'),preObj=pageObj.find('li.previous'), currentObj=pageObj.find('li').not('.previous,.disabled,.next'), nextObj=pageObj.find('li.next'); functionloopPageElement(minPage,maxPage){ vartempObj=preObj.next(); for(vari=minPage;i<=maxPage;i++){ if(minPage==1&&(preObj.next().attr('class').indexOf('hidden'))<0) preObj.next().addClass('hidden'); elseif(minPage>1&&(preObj.next().attr('class').indexOf('hidden'))>0) preObj.next().removeClass('hidden'); if(maxPage==totalPage&&(nextObj.prev().attr('class').indexOf('hidden'))<0) nextObj.prev().addClass('hidden'); elseif(maxPage<totalPage&&(nextObj.prev().attr('class').indexOf('hidden'))>0) nextObj.prev().removeClass('hidden'); varobj=tempObj.next().find('a'); if(!isNaN(obj.html()))obj.html(i); tempObj=tempObj.next(); } } functioncallBack(curr){ defaults.callback(curr,defaults.limit,totalCount); } currentObj.click(function(event){ event.preventDefault(); varcurrPage=Number($(this).find('a').html()),activeObj=pageObj.find('li[class="active"]'), activePage=Number(activeObj.find('a').html()); if(currPage==activePage)returnfalse; if(totalPage>showPage){ varmaxPage=currPage,minPage=1; if(($(this).prev().attr('class')) &&($(this).prev().attr('class').indexOf('disabled'))>=0){ minPage=currPage-1; maxPage=minPage+showPage-1; loopPageElement(minPage,maxPage); }elseif(($(this).next().attr('class')) &&($(this).next().attr('class').indexOf('disabled'))>=0){ if(totalPage-currPage>=1)maxPage=currPage+1; elsemaxPage=totalPage; if(maxPage-showPage>0)minPage=(maxPage-showPage)+1; loopPageElement(minPage,maxPage) } } activeObj.removeClass('active'); $.each(currentObj,function(index,thiz){ if($(thiz).find('a').html()==currPage){ $(thiz).addClass('active'); callBack(currPage); } }); }); preObj.click(function(event){ event.preventDefault(); varactiveObj=pageObj.find('li[class="active"]'),activePage=Number(activeObj.find('a').html()); if(activePage<=1)returnfalse; if(totalPage>showPage){ varmaxPage=activePage,minPage=1; if((activeObj.prev().prev().attr('class')) &&(activeObj.prev().prev().attr('class').indexOf('disabled'))>=0){ minPage=activePage-1; if(minPage>1)minPage=minPage-1; maxPage=minPage+showPage-1; loopPageElement(minPage,maxPage); } } $.each(currentObj,function(index,thiz){ if($(thiz).find('a').html()==(activePage-1)){ activeObj.removeClass('active'); $(thiz).addClass('active'); callBack(activePage-1); } }); }); nextObj.click(function(event){ event.preventDefault(); varactiveObj=pageObj.find('li[class="active"]'),activePage=Number(activeObj.find('a').html()); if(activePage>=totalPage)returnfalse; if(totalPage>showPage){ varmaxPage=activePage,minPage=1; //if((activeObj.next().next().attr('class')) //&&(activeObj.next().next().attr('class').indexOf('disabled'))>=0){ //maxPage=activePage+2; //if(maxPage>totalPage)maxPage=totalPage; //minPage=maxPage-showPage+1; //loopPageElement(minPage,maxPage); //} if((activeObj.next().next().attr('class')) &&(activeObj.next().next().attr('class').indexOf('disabled'))>=0){ maxPage=activePage+2; if(maxPage>totalPage)maxPage=totalPage; minPage=maxPage-showPage+1; loopPageElement(minPage,maxPage); } } $.each(currentObj,function(index,thiz){ if($(thiz).find('a').html()==(activePage+1)){ activeObj.removeClass('active'); $(thiz).addClass('active'); callBack(activePage+1); } }); }); } }; })(jQuery);
3.项目采用struts2,返回json,在struts中配置,并在action中使用map来封装数据,并添加get方法
struts.xml
<packagename="message"namespace="/"extends="struts-default,json-default"> <actionname="message_*"class="messageAction"method="{1}"> <resultname="index">/WEB-INF/jsp/message.jsp</result> <resultname="success"type="json"> <paramname="root">dataMap</param> </result> </action> </package>
action
packagecom.cdv.mediastar.action; importjava.io.IOException; importjava.text.ParseException; importjava.text.SimpleDateFormat; importjava.util.Date; importjava.util.HashMap; importjava.util.List; importjava.util.Map; importjavax.annotation.Resource; importjavax.servlet.http.HttpServletRequest; importjavax.servlet.http.HttpServletResponse; importorg.apache.log4j.Logger; importorg.apache.struts2.ServletActionContext; importorg.apache.struts2.json.annotations.JSON; importorg.springframework.context.annotation.Scope; importorg.springframework.stereotype.Controller; importcom.cdv.mediastar.model.Message; importcom.cdv.mediastar.service.MessageService; importcom.cdv.mediastar.util.PageParameter; importcom.opensymphony.xwork2.ActionSupport; @Scope("request") @Controller("messageAction") publicclassMessageActionextendsActionSupport{ /** * */ privatestaticfinallongserialVersionUID=3731009117710718470L; privateLoggerlogger=Logger.getLogger(MessageAction.class); @Resource privateMessageServicemessageService; Map<String,Object>dataMap=newHashMap<String,Object>(); publicMap<String,Object>getDataMap(){ returndataMap; } publicStringindex(){ HttpServletRequestrequest=ServletActionContext.getRequest(); PageParameterpage=newPageParameter(); intpageNo=page.getPageNo(); inttotalCount=messageService.count(null,null,null,0); inttotalPage=totalCount%page.getPageSize()==0?totalCount/page.getPageSize():totalCount/page.getPageSize()+1; intstartNum=1,stopNum=1; startNum=(pageNo-1)*page.getPageSize()+1; if((startNum+page.getPageSize()-1)<=totalCount){ stopNum=startNum+page.getPageSize()-1; }else{ stopNum=totalCount; } page.setTotalCount(totalCount); page.setTotalPage(totalPage); request.setAttribute("page",page); request.setAttribute("startNum",startNum); request.setAttribute("stopNum",stopNum); return"index"; } publicStringlist(){ dataMap.clear(); PageParameterpage=newPageParameter(); ints=0,max=page.getPageSize(); List<Message>messageListPage=messageService.find(null,null,null,s,max); inttotalCount=messageService.count(null,null,null,0); inttotalPage=totalCount%page.getPageSize()==0?totalCount/page.getPageSize():totalCount/page.getPageSize()+1; page.setTotalCount(totalCount); page.setTotalPage(totalPage); intstartNum=0,stopNum=0; startNum=1; if((startNum+page.getPageSize()-1)<=totalCount){ stopNum=startNum+page.getPageSize()-1; }else{ stopNum=totalCount; } dataMap.put("startNum",startNum); dataMap.put("stopNum",stopNum); dataMap.put("totalCount",totalCount); dataMap.put("totalPage",totalPage); dataMap.put("pageNo",page.getPageNo()); dataMap.put("messageListPage",messageListPage); return"success"; } publicStringdel(){ dataMap.clear(); HttpServletRequestrequest=ServletActionContext.getRequest(); Longid=Long.parseLong(request.getParameter("id")); intdeleteFlag=messageService.delete(id); if(deleteFlag>0){ dataMap.put("message","success"); }else{ dataMap.put("message","error"); } logger.info("rocky>>>>>>>>>>>>deletemessageflag======"+deleteFlag); return"success"; } publicStringsearch()throwsParseException,IOException{ dataMap.clear(); HttpServletRequestrequest=ServletActionContext.getRequest(); Datefrom=null,to=null; StringsearchDateStart=request.getParameter("searchDateStart"); if(searchDateStart!=null&&searchDateStart!=""){ from=newSimpleDateFormat("MM/dd/yyyy").parse(searchDateStart); } StringsearchDateEnd=request.getParameter("searchDateEnd"); if(searchDateEnd!=null&&searchDateEnd!=""){ to=newSimpleDateFormat("MM/dd/yyyy").parse(searchDateEnd); } Stringreceiver=request.getParameter("receiver"); StringpageNoStr=request.getParameter("pageNo"); PageParameterpage=newPageParameter(); intpageNo=page.getPageNo(); ints=0,max=page.getPageSize(); if(pageNoStr!=null&&pageNoStr!=""){ pageNo=Integer.parseInt(pageNoStr); s=(pageNo-1)*page.getPageSize(); } List<Message>messageListPage=messageService.find(receiver,from,to,s,max); inttotalCount=messageService.count(receiver,from,to,0); inttotalPage=totalCount%page.getPageSize()==0?totalCount/page.getPageSize():totalCount/page.getPageSize()+1; intstartNum=0,stopNum=0; startNum=(pageNo-1)*page.getPageSize()+1; if((startNum+page.getPageSize()-1)<=totalCount){ stopNum=startNum+page.getPageSize()-1; }else{ stopNum=totalCount; } dataMap.put("startNum",startNum); dataMap.put("stopNum",stopNum); dataMap.put("pageNo",pageNo); dataMap.put("totalCount",totalCount); dataMap.put("pageSize",page.getPageSize()); dataMap.put("searchDateStart",searchDateStart); dataMap.put("searchDateEnd",searchDateEnd); dataMap.put("receiver",receiver); dataMap.put("messageListPage",messageListPage); return"success"; } }
以上就是小编为大家带来的jsp页面列表展示ajax异步实现方法全部内容了,希望大家多多支持毛票票~