当前位置:首页 > JSP教程 > JSP常见问题

jsp页面列表展示ajax异步实现方法

1. 服务端先返回页面基本结构(如message.jsp),

<%@ page language="java" contenttype="text/html; charset=utf-8" pageencoding="utf-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> <% string path = request.getcontextpath(); string basepath = request.getscheme() + "://" + request.getservername() + ":" + request.getserverport() + path + "/"; %> <!doctype html> <!--[if lt ie 7]> <html class="ie ie6 lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]--> <!--[if ie 7]> <html class="ie ie7 lt-ie9 lt-ie8" lang="en"> <![endif]--> <!--[if ie 8]> <html class="ie ie8 lt-ie9" lang="en"> <![endif]--> <!--[if ie 9]> <html class="ie ie9" lang="en"> <![endif]--> <!--[if !ie]><!--> <html lang="en" class="no-ie"> <!--<![endif]--> <head> <!-- meta--> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"> <meta name="description" content=""> <meta name="keywords" content=""> <meta name="author" content=""> <title>消息中心</title> <!-- html5 shim and respond.js ie8 support of html5 elements and media queries --> <!--[if lt ie 9]><script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script><script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script><![endif]--> <!-- bootstrap css--> <link rel="stylesheet" href="<%=path %>/app/css/bootstrap.css"> <!-- vendor css--> <link rel="stylesheet" href="<%=path %>/vendor/fontawesome/css/font-awesome.min.css"> <link rel="stylesheet" href="<%=path %>/vendor/animo/animate+animo.css"> <!-- start page custom css--> <!-- data table styles--> <link rel="stylesheet" href="<%=path %>/vendor/datatable/extensions/datatable-bootstrap/css/datatables.bootstrap.css"> <link rel="stylesheet" href="<%=path %>/vendor/datatable/extensions/colvis/css/datatables.colvis.css"> <!-- end page custom css--> <!-- app css--> <link rel="stylesheet" href="<%=path %>/app/css/app.css"> <link rel="stylesheet" href="<%=path %>/app/css/beadmin-theme-c2.css"> <link rel="stylesheet" href="<%=path %>/vendor/sweetalert/lib/sweet-alert.css" /> <link rel="stylesheet" href="<%=path %>/css/page.css"/> <!-- modernizr js script--> <script src="<%=path %>/vendor/modernizr/modernizr.js" type="application/javascript"></script> <!-- fastclick for mobiles--> <script src="<%=path %>/vendor/fastclick/fastclick.js" type="application/javascript"></script>. <script> var basepath = '<%=basepath %>'; var pageno = ${page.pageno}; var totalcount = ${page.totalcount}; var totalpage = ${page>totalpage}; var pagesize = ${page.pagesize}; </script> </head> <body> <!-- start main wrapper--> <div class="wrapper" > <!-- start main section--> <section> <!-- start page content--> <div class="content-wrapper" style="margin-left:-250px;margin-top:-40px;"> <h3>消息中心 <!-- <div style="float:right; margin-top:5px;" class="form-group"> <button type="button" onclick="$('#mymodal').modal({backdrop: 'static', keyboard: false});;" class="btn btn-labeled btn-success"> <span class="btn-label"><i class="fa fa-plus"></i> </span>添加</button> </div>--> <small>消息管理</small> </h3> <!-- start panel--> <!-- start datatable 3--> <div class="row"> <div class="col-lg-12"> <div class="panel panel-default"> <div class="panel-heading" style="border-bottom:1px solid #eee;"> <form class="form-inline" id="searchform" method="post" action="<%=path %>/page/messagesearch.action"> <div class="form-group"> <b>创建时间:  </b> <div class="datetimepicker input-group date mb-lg" data-pick-time="false"> <input type="text" class="form-control" id="searchdatestart" name="searchdatestart" value='' disabled="disabled"> <span class="input-group-addon"> <span class="fa-calendar fa"></span> </span> </div> <span style="margin-top:-8px;">—</span> <div class="datetimepicker input-group date mb-lg" data-pick-time="false"> <input type="text" class="form-control" id="searchdateend" name="searchdateend" value='' disabled="disabled"> <span class="input-group-addon"> <span class="fa-calendar fa"></span> </span> </div> </div> <div class="form-group"> <b>接收者: </b> <input type="text" class="form-control mb-lg" id="receiver" name="receiver" value=''> </div> <div class="form-group"> <a style="margin:-10px 0 0 5px; float:left;" href="javascript:void(0);" class="mb-sm btn btn-primary" type="button" id="searchmessage">搜索</a> </div> <input type="hidden" id="pageno" name="pageno" value=''> </form> </div> <div class="table-responsive"> <table class="table table-bordered table-hover datatable no-footer" id="table-ext-1" > <thead> <tr> <th style="width:300px;">描述</th> <th class="sorting center" tabindex="0" aria-controls="datatable1" rowspan="1" colspan="1" style="width: 86px;" aria-label="rendering engine: activate to sort column ascending">发送者</th> <th class="sorting center" tabindex="0" aria-controls="datatable1" rowspan="1" colspan="1" style="width: 86px;" aria-label="rendering engine: activate to sort column ascending">接收者</th> <th class="sorting center" tabindex="0" aria-controls="datatable1" rowspan="1" colspan="1" style="width: 86px;" aria-label="rendering engine: activate to sort column ascending">创建时间</th> <th class="th150 center">操作</th> </tr> </thead> <tbody id="message_body"> </tbody> <tfoot> <tr> </tr> </tfoot> </table> </div> <div class="panel-footer"> <div class="row"> <div style="line-height:35px;" class="col-lg-3"> <div class="input-group pull-left" id="message_showlines"> </div> </div> <div class="col-lg-9"></div> <div class="tcdpagecode"></div> </div> </div> </div> </div> </div> <!-- end datatable 3--> </div> <!-- end page content--> </section> <!-- end main section--> </div> <!-- end main wrapper--> <!-- start modal--> <div id="mymodal" tabindex="-1" role="dialog" aria-labelledby="mymodallabel" aria-hidden="true" class="modal" > <div class="modal-dialog" style="width:600px;"> <div class="modal-content"> <div class="modal-header"> <button type="button" data-dismiss="modal" aria-hidden="true" class="close">×</button> <h4 id="mymodallabel" class="modal-title">新建应用</h4> </div> <div class="modal-body" style="padding-right:20px;"> <form method="get" action="/" class="form-horizontal"> <fieldset> <div class="form-group" style="padding-bottom:5px;"> <label class="col-sm-2 control-label">名称</label> <div class="col-sm-10"> <input type="text" class="form-control"> </div> </div> <div class="form-group" style="margin-top:10px;"> <label class="col-sm-2 control-label">描述</label> <div class="col-sm-10"> <input type="text" class="form-control"> </div> </div> <div class="form-group" style="margin-top:10px;"> <label class="col-sm-2 control-label">url</label> <div class="col-sm-10"> <input type="text" class="form-control"> </div> </div> <div class="form-group" style="margin-top:5px;"> <label class="col-sm-2 control-label">类别</label> <div class="col-sm-10"> <select class="form-control m-b" name="account"> <option>web</option> <option>mobile</option> </select></div> </div> <div class="form-group" style="margin-top:5px;"> <label class="col-sm-2 control-label">授权模式</label> <div class="col-sm-10"> <select class="form-control m-b" name="account"> <option>授权</option> <option>不授权</option> </select></div> </div> <div class="form-group" style="margin-top:10px;"> <label class="col-sm-2 control-label">logo</label> <div class="col-sm-10"> <input type="button" class="form-control"> </div> </div> </fieldset> </form> </div> </fieldset> <div class="modal-footer"> <button type="button" data-dismiss="modal" class="btn btn-default">取消</button> <button type="button" class="btn btn-primary">确定</button> </div> </div> </div> </div> </div> <div id="mymodal2" tabindex="-1" role="dialog" aria-labelledby="mymodallabel" aria-hidden="true" class="modal"> <div class="modal-dialog" style="width:650px;"> <div class="modal-content"> <div class="modal-header"> <button type="button" data-dismiss="modal" aria-hidden="true" class="close">×</button> <h4 id="mymodallabel" class="modal-title">修改密码</h4> </div> <div class="modal-body"> <form method="get" action="/" class="form-horizontal"> <fieldset> <div class="form-group" style="padding-bottom:5px;"> <label class="col-sm-2 control-label">原密码</label> <div class="col-sm-10"> <input type="text" class="form-control"> </div> </div> <div class="form-group" style="padding-bottom:5px;"> <label class="col-sm-2 control-label">新密码</label> <div class="col-sm-10"> <input type="password" name="password" class="form-control"> </div> </div> <div class="form-group" style="padding-bottom:5px;"> <label class="col-sm-2 control-label">确认密码</label> <div class="col-sm-10"> <input type="password" name="password" class="form-control"> </div> </div> </fieldset> </form> </div> <div class="modal-footer"> <button type="button" data-dismiss="modal" class="btn btn-default">关闭</button> <button type="button" class="btn btn-primary">save changes</button> </div> </div> </div> </div> <div id="mymodal3" tabindex="-1" role="dialog" aria-labelledby="mymodallabel" aria-hidden="true" class="modal"> <div class="modal-dialog" style="width:600px;"> <div class="modal-content"> <div class="modal-header"> <button type="button" data-dismiss="modal" aria-hidden="true" class="close">×</button> <h4 id="mymodallabel" class="modal-title">编辑节目特殊单</h4> </div> <div class="modal-body"> <form method="get" action="/" class="form-horizontal"> <fieldset> <div class="form-group" style="padding-bottom:5px;"> <label class="col-sm-2 control-label">表单标题</label> <div class="col-sm-10"> <input type="text" class="form-control"> </div> </div> </fieldset> </form> </div> <div class="modal-footer"> <button type="button" data-dismiss="modal" class="btn btn-default">关闭</button> <button type="button" class="btn btn-primary">确定</button> </div> </div> </div> </div> <!-- end modal --> <form method="post" id="pageform" name="pageform" action="<%=path%>/page/message_search.action"> <input type="hidden" id="pageno" name="pageno" value="" /> </form> <!-- start scripts--> <!-- main vendor scripts--> <script src="<%=path %>/vendor/jquery/jquery.min.js"></script> <script src="<%=path %>/vendor/bootstrap/js/bootstrap.min.js"></script> <!-- plugins--> <script src="<%=path %>/vendor/chosen/chosen.jquery.min.js"></script> <script src="<%=path %>/vendor/slider/js/bootstrap-slider.js"></script> <script src="<%=path %>/vendor/filestyle/bootstrap-filestyle.min.js"></script> <!-- animo--> <script src="<%=path %>/vendor/animo/animo.min.js"></script> <!-- sparklines--> <script src="<%=path %>/vendor/sparklines/jquery.sparkline.min.js"></script> <!-- momentjs and datepicker--> <script src="<%=path %>/vendor/moment/min/moment-with-langs.js"></script> <script src="<%=path %>/vendor/datetimepicker/js/bootstrap-datetimepicker.min.js"></script> <!-- slimscroll--> <script src="<%=path %>/vendor/slimscroll/jquery.slimscroll.min.js"></script> <!-- store + json--> <script src="<%=path %>/vendor/store/store+json2.min.js"></script> <!-- screenfull--> <script src="<%=path %>/vendor/screenfull/screenfull.min.js"></script> <!-- start page custom script--> <!-- data table scripts--> <script src="<%=path %>/vendor/datatable/media/js/jquery.datatables.min.js"></script> <script src="<%=path %>/vendor/datatable/extensions/datatable-bootstrap/js/datatables.bootstrap.js"></script> <script src="<%=path %>/vendor/datatable/extensions/datatable-bootstrap/js/datatables.bootstrappagination.js"></script> <script src="<%=path %>/vendor/datatable/extensions/colvis/js/datatables.colvis.min.js"></script> <!-- start page custom script--> <script src="<%=path %>/vendor/wizard/js/bwizard.min.js"></script> <!-- form validation--> <script src="<%=path %>/vendor/parsley/parsley.min.js"></script> <!-- end page custom script--> <!-- app main--> <script src="<%=path %>/app/js/app.js"></script> <script src="<%=path %>/vendor/sweetalert/lib/sweet-alert.min.js"></script> <script src="<%=path %>/script/message.js"></script> <script src="<%=path %>/page/js/page.js"></script> <!-- end scripts--> </body> </html>

2. example.js加载的时候,再去异步请求获取页面数据(表格、分页等),再动态创建表,分页链接等

$(function(){ inittable(); $("#searchmessage").on("click",function(){ messagesearch(pageno); }); //获取message列表 "pageno" : pageno function inittable(){ $.ajax({ url : basepath + "page/message_list.action", type : "get", datatype : "json", success : function(datamap){ createtbody(datamap); createtfoot(datamap); }, error : function(errordata){ } }); } //查询message function messagesearch(pageno){ var searchdatestart = $("#searchdatestart").val(); var searchdateend = $("#searchdateend").val(); var startdate = new date(searchdatestart); var enddate = new date(searchdateend); var num = enddate - startdate; if(num<0){ $("#searchdateend").val(''); swal({ title: "结束日期不能晚于开始日期", text: "", type: "error" }); return false; } var receiver = $("#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){ } }); } function createtbody(datamap){ if(datamap!=null){ var messagelistpage = datamap.messagelistpage; var html = []; for(var i=0; i<messagelistpage.length; i++){ var message = messagelistpage[i]; var ctime = message.createtime.replace(/t/g," "); html.push('<tr class="gradex center">'); html.push('<td style="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('<td message_id=' + message.id + '><a href="#" class="message_del btn btn-danger btn-xs"> 删除 </a></td>'); html.push('</tr>'); } $("#message_body").empty().html(html.join('')); } } function createtfoot(datamap){ if(datamap!=null){ startnum = datamap.startnum; stopnum = datamap.stopnum; totalcount = datamap.totalcount; pageno = datamap.pageno; pagesize = datamap.pagesize; var str = '显示 ' + startnum + '至' + stopnum + '项 , 共' + totalcount +' 项。'; $("#message_showlines").html(str); } } $('#message_body').on('click','a.message_del',function(){ var message_id = $(this).parent("td").attr("message_id"); swal({ title : "确认要删除吗?", text : "删除后将不能恢复!", type : "warning", showcancelbutton : true, confirmbuttoncolor : "#dd6b55", confirmbuttontext : "yes, delete it!", cancelbuttontext : "no, cancel plx!", 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", "your imaginary file is safe :)", "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

/** * created by hope on 2014/12/28. */ (function ($) { $.fn.extendpagination = function (options) { var defaults = { pageid:'', totalcount: '', showpage: '10', limit: '5', callback: function () { return false; } }; $.extend(defaults, options || {}); // alert(defaults.pageid); if (defaults.totalcount == '') { //alert('总数不能为空!'); $(this).empty(); return false; } else if (number(defaults.totalcount) <= 0) { //alert('总数要大于0!'); $(this).empty(); return false; } if (defaults.showpage == '') { defaults.showpage = '10'; } else if (number(defaults.showpage) <= 0)defaults.showpage = '10'; if (defaults.limit == '') { defaults.limit = '5'; } else if (number(defaults.limit) <= 0)defaults.limit = '5'; var totalcount = number(defaults.totalcount), showpage = number(defaults.showpage), limit = number(defaults.limit), totalpage = math.ceil(totalcount / limit); if (totalpage > 0) { var html = []; html.push(' <ul class="pagination">'); html.push(' <li class="previous"><a href="#">«</a></li>'); html.push('<li class="disabled hidden"><a href="#">...</a></li>'); if (totalpage <= showpage) { for (var i = 1; i <= totalpage; i++) { if (i == defaults.pageid) html.push(' <li class="active"><a href="#">' + i + '</a></li>'); else html.push(' <li><a href="#">' + i + '</a></li>'); } } else { for (var j = 1; j <= showpage; j++) { if (j == defaults.pageid) html.push(' <li class="active"><a href="#">' + j + '</a></li>'); else html.push(' <li><a href="#">' + j + '</a></li>'); } } html.push('<li class="disabled hidden"><a href="#">...</a></li>'); html.push('<li class="next"><a href="#">»</a></li></ul>'); $(this).html(html.join('')); if (totalpage > showpage) $(this).find('ul.pagination li.next').prev().removeclass('hidden'); var pageobj = $(this).find('ul.pagination'), preobj = pageobj.find('li.previous'), currentobj = pageobj.find('li').not('.previous,.disabled,.next'), nextobj = pageobj.find('li.next'); function looppageelement(minpage, maxpage) { var tempobj = preobj.next(); for (var i = minpage; i <= maxpage; i++) { if (minpage == 1 && (preobj.next().attr('class').indexof('hidden')) < 0) preobj.next().addclass('hidden'); else if (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'); else if (maxpage < totalpage && (nextobj.prev().attr('class').indexof('hidden')) > 0) nextobj.prev().removeclass('hidden'); var obj = tempobj.next().find('a'); if (!isnan(obj.html()))obj.html(i); tempobj = tempobj.next(); } } function callback(curr) { defaults.callback(curr, defaults.limit, totalcount); } currentobj.click(function (event) { event.preventdefault(); var currpage = number($(this).find('a').html()), activeobj = pageobj.find('li[class="active"]'), activepage = number(activeobj.find('a').html()); if (currpage == activepage) return false; if (totalpage > showpage) { var maxpage = 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); } else if (($(this).next().attr('class')) && ($(this).next().attr('class').indexof('disabled')) >= 0) { if (totalpage - currpage >= 1) maxpage = currpage + 1; else maxpage = 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(); var activeobj = pageobj.find('li[class="active"]'), activepage = number(activeobj.find('a').html()); if (activepage <= 1) return false; if (totalpage > showpage) { var maxpage = 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(); var activeobj = pageobj.find('li[class="active"]'), activepage = number(activeobj.find('a').html()); if (activepage >= totalpage) return false; if (totalpage > showpage) { var maxpage = 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

<package name="message" namespace="/" extends="struts-default, json-default"> <action name="message_*" class="messageaction" method="{1}"> <result name="index">/web-inf/jsp/message.jsp</result> <result name="success" type="json"> <param name="root">datamap</param> </result> </action> </package>

action

package com.cdv.mediastar.action; import java.io.ioexception; import java.text.parseexception; import java.text.simpledateformat; import java.util.date; import java.util.hashmap; import java.util.list; import java.util.map; import javax.annotation.resource; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import org.apache.log4j.logger; import org.apache.struts2.servletactioncontext; import org.apache.struts2.json.annotations.json; import org.springframework.context.annotation.scope; import org.springframework.stereotype.controller; import com.cdv.mediastar.model.message; import com.cdv.mediastar.service.messageservice; import com.cdv.mediastar.util.pageparameter; import com.opensymphony.xwork2.actionsupport; @scope("request") @controller("messageaction") public class messageaction extends actionsupport { /** * */ private static final long serialversionuid = 3731009117710718470l; private logger logger = logger.getlogger(messageaction.class); @resource private messageservice messageservice; map<string, object> datamap = new hashmap<string, object>(); public map<string, object> getdatamap() { return datamap; } public string index(){ httpservletrequest request = servletactioncontext.getrequest(); pageparameter page = new pageparameter(); int pageno = page.getpageno(); int totalcount = messageservice.count(null, null, null, 0); int totalpage = totalcount%page.getpagesize()==0?totalcount/page.getpagesize():totalcount/page.getpagesize()+1; int startnum = 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"; } public string list(){ datamap.clear(); pageparameter page = new pageparameter(); int s = 0, max = page.getpagesize(); list<message> messagelistpage = messageservice.find(null, null, null, s, max); int totalcount = messageservice.count(null, null, null, 0); int totalpage = totalcount%page.getpagesize()==0?totalcount/page.getpagesize():totalcount/page.getpagesize()+1; page.settotalcount(totalcount); page.settotalpage(totalpage); int startnum = 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"; } public string del(){ datamap.clear(); httpservletrequest request = servletactioncontext.getrequest(); long id = long.parselong(request.getparameter("id")); int deleteflag = messageservice.delete(id); if(deleteflag>0){ datamap.put("message", "success"); }else{ datamap.put("message", "error"); } logger.info("rocky>>>>>>>>>>>>delete message flag======"+deleteflag); return "success"; } public string search() throws parseexception, ioexception{ datamap.clear(); httpservletrequest request = servletactioncontext.getrequest(); date from = null, to = null ; string searchdatestart = request.getparameter("searchdatestart"); if(searchdatestart!=null && searchdatestart!="") { from = new simpledateformat("mm/dd/yyyy").parse(searchdatestart); } string searchdateend = request.getparameter("searchdateend"); if(searchdateend!=null && searchdateend!="") { to = new simpledateformat("mm/dd/yyyy").parse(searchdateend); } string receiver = request.getparameter("receiver"); string pagenostr = request.getparameter("pageno"); pageparameter page = new pageparameter(); int pageno = page.getpageno(); int s = 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); int totalcount = messageservice.count(receiver, from, to, 0); int totalpage = totalcount%page.getpagesize()==0?totalcount/page.getpagesize():totalcount/page.getpagesize()+1; int startnum = 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异步实现方法全部内容了,希望大家多多支持硕编程~



【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐