1、实体类
importjava.util.ArrayList;
publicclassObjectType {
privateString type;
privateArrayList subObjects;
publicString getType() {
returntype;
}
publicvoidsetType(String type) {
this.type = type;
}
publicArrayList getSubObjects() {
returnsubObjects;
}
publicvoidsetSubObjects(ArrayList subObjects) {
this.subObjects = subObjects;
}
}
import java.util.ArrayList;
public class ObjectType {
private String type;
private ArrayList subObjects;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public ArrayList getSubObjects() {
return subObjects;
}
public void setSubObjects(ArrayList subObjects) {
this.subObjects = subObjects;
}
}
publicclassSubObjectType {
privateString subtype;
privatedoublefileCount;
privatedoublebytes;
privateString timeRange;
publicString getSubtype() {
returnsubtype;
}
publicvoidsetSubtype(String subtype) {
this.subtype = subtype;
}
publicdoublegetFileCount() {
returnfileCount;
}
publicvoidsetFileCount(doublefileCount) {
this.fileCount = fileCount;
}
publicdoublegetBytes() {
returnbytes;
}
publicvoidsetBytes(doublebytes) {
this.bytes = bytes;
}
publicString getTimeRange() {
returntimeRange;
}
publicvoidsetTimeRange(String timeRange) {
this.timeRange = timeRange;
}
}
public class SubObjectType {
private String subtype;
private double fileCount;
private double bytes;
private String timeRange;
public String getSubtype() {
return subtype;
}
public void setSubtype(String subtype) {
this.subtype = subtype;
}
public double getFileCount() {
return fileCount;
}
public void setFileCount(double fileCount) {
this.fileCount = fileCount;
}
public double getBytes() {
return bytes;
}
public void setBytes(double bytes) {
this.bytes = bytes;
}
public String getTimeRange() {
return timeRange;
}
public void setTimeRange(String timeRange) {
this.timeRange = timeRange;
}
}
2、servlet:得到一个对象列表ArrayList,将其转化为jsonArray
AccountInfoDao dao =newAccountInfoDao();
ArrayList objectTypes =newArrayList();
objectTypes = dao.load();
JSONObject jsonObject =newJSONObject();
jsonObject.put("categorys", objectTypes);
JSONArray jsonArray =newJSONArray();
jsonArray.add(jsonObject);
System.out.println(jsonArray);
PrintWriter out = response.getWriter();
out.write(jsonArray.toString());
AccountInfoDao dao = new AccountInfoDao();
ArrayList objectTypes = new ArrayList();
objectTypes = dao.load();
JSONObject jsonObject = new JSONObject();
jsonObject.put("categorys", objectTypes);
JSONArray jsonArray = new JSONArray();
jsonArray.add(jsonObject);
System.out.println(jsonArray);
PrintWriter out = response.getWriter();
out.write(jsonArray.toString());
3、js处理:
functionload(){
$.ajax({
type:"post",//请求方式
url:"servlet/AccountInfo",//发送请求地址
dataType:"json",
data:{//发送给数据库的数据
},
//请求成功后的回调函数有两个参数
success:function(data,textStatus){
varobjs=eval(data);//解析json对象
varobj = objs[0];
vartable = $("#table");
table.empty();
table.append('
类别文件个数文件大小时间范围');if(obj==null|| obj==""){
table.append('
暂无数据!')//$("#page").hide();
returnfalse;
}
varcategorys = obj.categorys;
for(vari=0;i
vartype = categorys[i].type;
varsubObjects = categorys[i].subObjects;
varlen = subObjects.length;
table.append('
'+type+''+''+subObjects[0].subtype+''+''+subObjects[0].fileCount+''+''+subObjects[0].bytes+''+''+subObjects[0].timeRange+'')//table.append('
'+subObjects[0].subtype+''+''+subObjects[0].fileCount+''+''+subObjects[0].bytes+''+''+subObjects[0].timeRange+'');for(varj=1;j
table.append('
'+subObjects[j].subtype+''+''+subObjects[j].fileCount+''+''+subObjects[j].bytes+''+''+subObjects[j].timeRange+'');}
}
//为鼠标移动添加样式,鼠标所在行变色,鼠标离开行恢复原状
$("tr:even").addClass("even");
$("th").first().css("text-align","left");
$("th").first().css("padding-left","5px");
$("tr").mouseenter(function(){
$(this).addClass('bs');
});
$("tr").mouseleave(function(){
$(this).removeClass('bs');
});
}
});
}
function load(){
$.ajax({
type:"post",//请求方式
url:"servlet/AccountInfo",//发送请求地址
dataType:"json",
data:{//发送给数据库的数据
},
//请求成功后的回调函数有两个参数
success:function(data,textStatus){
var objs=eval(data); //解析json对象
var obj = objs[0];
var table = $("#table");
table.empty();
table.append('
类别文件个数文件大小时间范围');if(obj==null || obj==""){
table.append('
暂无数据!')//$("#page").hide();
return false;
}
var categorys = obj.categorys;
for(var i=0;i
var type = categorys[i].type;
var subObjects = categorys[i].subObjects;
var len = subObjects.length;
table.append('
'+type+''+''+subObjects[0].subtype+''+''+subObjects[0].fileCount+''+''+subObjects[0].bytes+''+''+subObjects[0].timeRange+'')//table.append('
'+subObjects[0].subtype+''+''+subObjects[0].fileCount+''+''+subObjects[0].bytes+''+''+subObjects[0].timeRange+'');for(var j=1;j
table.append('
'+subObjects[j].subtype+''+''+subObjects[j].fileCount+''+''+subObjects[j].bytes+''+''+subObjects[j].timeRange+'');}
}
//为鼠标移动添加样式,鼠标所在行变色,鼠标离开行恢复原状
$("tr:even").addClass("even");
$("th").first().css("text-align","left");
$("th").first().css("padding-left","5px");
$("tr").mouseenter(function(){
$(this).addClass('bs');
});
$("tr").mouseleave(function(){
$(this).removeClass('bs');
});
}
});
}
4、jsp页面
类别文件大小文件个数时间范围类别 | 文件大小 | 文件个数 | 时间范围 |
---|