jsp中的內容
請注意responseHandler: function (res)中的內容。
在下面,先是定義了一個id爲calcul的label標籤,然後我將通過responseHandler函數,在該標籤中顯示從servlet中傳回來的別的參數。
<label style=" float:bottom;font-size: 13px;padding: 5px 10px 0px 10px;" id="calcul"></label>
<script type="text/javascript">
var TableInit=function(){
var oTableInit = new Object();
oTableInit.Init=function(){
$('#reportTable').bootstrapTable({
method: 'get',
url: "<c:url value='/IP_IndexServlet?act="+state+"&&mIP="+mIP+"&&start="+StartSearch+"&&end="+EndSearch+"'/>", //獲取數據的Servlet地址
queryParams: function queryParams(params) { //設置查詢參數
var param = {
pageNumber: params.pageNumber,
pageSize: params.pageSize,
};
return param;
},
cache: false,
//height: 750,
striped: true,
pagination: true,
silent: true, //以靜默方式刷新數據
toolbar:"#toolbar",
locale:"zh-US", //表格漢化
sidePagination: "client",
pageSize: 10,
pageNumber:mPage,
pageList: [10, 14,15, 16, 18,20],
search: true,
showColumns: true,
showRefresh: true,
showExport: true,
exportDataType: 'all',
clickToSelect: true,
exportTypes:[ 'excel','xlsx','doc','csv', 'txt', 'sql' ],
exportOptions:{
//ignoreColumn: [12,14], //忽略某一列的索引
fileName: '數據導出', //文件名稱設置
worksheetName: 'Sheet1', //表格工作區名稱
tableName: 'IP數據表',
excelstyles: ['background-color', 'color', 'font-size', 'font-weight'],
//onMsoNumberFormat: DoOnMsoNumberFormat
},
columns : [{
field : '序號',
title : '序號'
}, {
field : '類型',
title : '類型'
}, {
field : '品牌',
title : '品牌'
}, {
field : '操作系統',
title : '操作系統'
}, {
field : 'IP地址',
title : 'IP地址'
}, {
field : 'MAC地址',
title : 'MAC地址'
}, {
field : '責任單位',
title : '責任單位'
}, {
field : '責任人',
title : '責任人'
}, {
field : '用戶名',
title : '用戶名'
}, {
field : '密碼',
title : '密碼'
}, {
field : '接入地點',
title : '接入地點'
}, {
field : '最後修改時間',
title : '最後修改時間'
}, {
field : '是否分配',
title : '是否分配'
}, {
field : '備註',
title : '用途'
},{
field: 'operate',
title: '操作',
align: 'center',
events: operateEvents,//給按鈕註冊事件
formatter: operateFormatter
}],
responseHandler: function (res) {
$("#calcul").html("<p>這是第一個參數的值 "+res.mCount+" </p><p>這是第二個參數的值 "+res.mTime+" </p>");
return{ //return bootstrap-table能處理的數據格式
"total":res.total,
"rows":res.rows
}
},
});
//隱藏正在加載
//$('#reportTable').bootstrapTable('hideLoading');
};
oTableInit.destroy=function(){
$("#reportTable").bootstrapTable('destroy');
}
return oTableInit;
}
var oTable = new TableInit();
oTable.destroy();
oTable.Init();
</script>
servlet中的內容
下面是servlet中的內容
response.setContentType("text/json; charset=utf-8");
PrintWriter out = response.getWriter();
JSONArray jsonarray = new JSONArray();
try {
ipd.IP_CreateTable(mIP);
} catch (SQLException e1) {
// TODO 自動生成的 catch 塊
e1.printStackTrace();
}
//獲取全部的IP信息
Result result=ipd.SelectAll(mIP);
for(int i=0;i<result.getRowCount();i++) {
Map rst=result.getRows()[i];
JSONObject jsonobj = new JSONObject();
jsonobj.put("序號", rst.get("序號"));
jsonobj.put("類型", rst.get("類型"));
jsonobj.put("品牌", rst.get("品牌"));
jsonobj.put("操作系統", rst.get("操作系統"));
jsonobj.put("IP地址", rst.get("IP地址"));
jsonobj.put("MAC地址", rst.get("MAC地址"));
jsonobj.put("責任單位", rst.get("責任單位"));
jsonobj.put("責任人", rst.get("責任人"));
jsonobj.put("用戶名", rst.get("用戶名"));
jsonobj.put("密碼", rst.get("密碼"));
jsonobj.put("接入地點", rst.get("接入地點"));
jsonobj.put("最後修改時間", rst.get("最後修改時間"));
jsonobj.put("是否分配", rst.get("是否分配"));
jsonobj.put("備註", rst.get("備註"));
jsonarray.add(jsonobj);
}
int length = jsonarray.size();
int count=0;
double titHour=0;
JSONObject jsonobj1 = new JSONObject();
jsonobj1.put("total", length);
jsonobj1.put("rows", jsonarray);
jsonobj1.put("mTime", titHour);//這是將在標籤中顯示的值1
jsonobj1.put("mCount", count);//這是將在標籤中顯示的值2
out = response.getWriter();
out.println(jsonobj1);