} //list是查询的结果集,i存储过程直接取出的字段数 public List Count(List list,int i){ List listCount=new ArrayList(); int m=list.size(); int c[][] = new int[m][i];//存储查询结果数组 int l1=0; int l2=0; Iterator it = null; it = list.iterator(); switch(i){ case 21: while (it.hasNext()){ int l=0; PersonStat personstat=(PersonStat)it.next();//循环遍历把结果放到数组里 c[l1][l++]=personstat.getC2(); c[l1][l++]=personstat.getC3(); c[l1][l++]=personstat.getC4(); c[l1][l++]=personstat.getC5(); c[l1][l++]=personstat.getC6(); c[l1][l++]=personstat.getC7(); c[l1][l++]=personstat.getC8(); c[l1][l++]=personstat.getC9(); c[l1][l++]=personstat.getC10(); c[l1][l++]=personstat.getC11(); c[l1][l++]=personstat.getC12(); c[l1][l++]=personstat.getC14(); c[l1][l++]=personstat.getC15(); c[l1][l++]=personstat.getC16(); c[l1][l++]=personstat.getC17(); c[l1][l++]=personstat.getC18(); c[l1][l++]=personstat.getC19(); c[l1][l++]=personstat.getC20(); l1++; } int c1[][]=new int[m][i];//临时数组
//idname 显示合计值的位置的标识名
//rowsstart 合计起始行
//rowsend 合计结束行
//columnstart 合计开始列
//columnend 合计结束列function rp(str) {//去空格
str=str.replace(/(^\s*)|(\s*$)/g,"");
return str;
}
function sum(tablename,idname,rowsstart,rowsend,columnstart,columnend)
{
o=document.getElementById(tablename);
var e;
if(rowsend==""||rowsend==null){//判断结束行的值,假设传递的参数项没有此值,取总行数做默认值.
rowsend=o.rows.length;
}
for(i=rowsstart;i<o.rows.length;i++) //行数循环
{ var sum=0;
var flag=0;
var sumShow=idname+(i-rowsstart);
for(j=columnstart;j<o.rows[i].cells.length;j++){//列循环 e=o.rows[i].cells[j].innerHTML;
e=rp(e);
if(!isNaN(parseInt(e))){
sum=sum+parseInt(e);//计算和 flag=1;
}
if(columnend==""||columnend==null){//判断结束列是否传递值,没有传递就取总的列数做默认值 columnend=o.rows[i].cells.length;
}
if(j==columnend){//判断是否取到目的结束列,true结束循环,显示结果,否则继续循环.
if(document.getElementById(sumShow)!=null&&flag==1){//当第一次加载页面时,没有结果则不显示此项
document.getElementById(sumShow).innerHTML=sum;
}
break;
}
}
if(i==rowsend){
break;
}
}
}
<%int i=0; %>
<%int j=0; %>
<logic:present name="liststatframe">
<logic:iterate id="result" name="liststatframe">
<tr bordercolor="#000000">
<td class="td1"><bean:write name="result" property="dw" /></td>
<td class="td1" id=sum<%=i++%> ></td>
<td class="td1"><bean:write name="result" property="c2" /></td>
<td class="td1"><bean:write name="result" property="c3" /></td>
<td class="td1"><bean:write name="result" property="c4" /></td>
<td class="td1"><bean:write name="result" property="c5" /></td>
<td class="td1"><bean:write name="result" property="c6" /></td>
<td class="td1"><bean:write name="result" property="c7" /></td>
<td class="td1"><bean:write name="result" property="c8" /></td>
<td class="td1"><bean:write name="result" property="c9" /></td>
<td class="td1"><bean:write name="result" property="c10" /></td>
<td class="td1"><bean:write name="result" property="c11" /></td>
<td class="td1"><bean:write name="result" property="c12" /></td>
<td class="td1" id=suma<%=j++%> ></td>
<td class="td1"><bean:write name="result" property="c14" /></td>
<td class="td1"><bean:write name="result" property="c15" /></td>
<td class="td1"><bean:write name="result" property="c16" /></td>
<td class="td1"><bean:write name="result" property="c17" /></td>
<td class="td1"><bean:write name="result" property="c18" /></td>
<td class="td1"><bean:write name="result" property="c19" /></td>
<td class="td1"><bean:write name="result" property="c20" /></td>
</tr>
</logic:iterate>
</logic:present>
感觉js简单点而已,毕竟只是用于显示,不过也是 要是禁用JS的话……囧~哈哈
顺手附上package com.cgtech.struts.actions.stat.personstat;import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;import com.cgtech.component.stat.personstat.PersonStat;
import com.cgtech.component.stat.workstat.WorkStat;
import com.cgtech.component.workresult.WxGzjg;public class CountStat {
//此方法用于统计表合计计算
public CountStat(){
}
//list是查询的结果集,i存储过程直接取出的字段数
public List Count(List list,int i){
List listCount=new ArrayList();
int m=list.size();
int c[][] = new int[m][i];//存储查询结果数组
int l1=0;
int l2=0;
Iterator it = null;
it = list.iterator();
switch(i){
case 21:
while (it.hasNext()){
int l=0;
PersonStat personstat=(PersonStat)it.next();//循环遍历把结果放到数组里
c[l1][l++]=personstat.getC2();
c[l1][l++]=personstat.getC3();
c[l1][l++]=personstat.getC4();
c[l1][l++]=personstat.getC5();
c[l1][l++]=personstat.getC6();
c[l1][l++]=personstat.getC7();
c[l1][l++]=personstat.getC8();
c[l1][l++]=personstat.getC9();
c[l1][l++]=personstat.getC10();
c[l1][l++]=personstat.getC11();
c[l1][l++]=personstat.getC12();
c[l1][l++]=personstat.getC14();
c[l1][l++]=personstat.getC15();
c[l1][l++]=personstat.getC16();
c[l1][l++]=personstat.getC17();
c[l1][l++]=personstat.getC18();
c[l1][l++]=personstat.getC19();
c[l1][l++]=personstat.getC20();
l1++;
}
int c1[][]=new int[m][i];//临时数组
for(int l=0;l<18;l++){//计算合计数 for(l1=0;l1<m;l1++){
c1[0][l]=c1[0][l]+c[l1][l];
}
}
int a[]=new int[4];
a[0]=c1[0][0]+c1[0][1]+c1[0][2];
a[1]=c1[0][11]+c1[0][12]+c1[0][13]+c1[0][14]+c1[0][15]+c1[0][16]+c1[0][17];
PersonStat personstat=new PersonStat();//存放结果到实体 personstat.setC1(a[0]);
personstat.setC2(c1[0][0]);
personstat.setC3(c1[0][1]);
personstat.setC4(c1[0][2]);
personstat.setC5(c1[0][3]);
personstat.setC6(c1[0][4]);
personstat.setC7(c1[0][5]);
personstat.setC8(c1[0][6]);
personstat.setC9(c1[0][7]);
personstat.setC10(c1[0][8]);
personstat.setC11(c1[0][9]);
personstat.setC12(c1[0][10]);
personstat.setC13(a[1]);
personstat.setC14(c1[0][11]);
personstat.setC15(c1[0][12]);
personstat.setC16(c1[0][13]);
personstat.setC17(c1[0][14]);
personstat.setC18(c1[0][15]);
personstat.setC19(c1[0][16]);
personstat.setC20(c1[0][17]);
listCount.add(personstat);//放到列表中方便页面调用 break;
case 19:
while (it.hasNext()){
int l=0;
WorkStat workstat=(WorkStat)it.next();
c[l2][l++]=workstat.getC2();
c[l2][l++]=workstat.getC3();
c[l2][l++]=workstat.getC4();
c[l2][l++]=workstat.getC5();
c[l2][l++]=workstat.getC6();
c[l2][l++]=workstat.getC7();
c[l2][l++]=workstat.getC8();
c[l2][l++]=workstat.getC9();
c[l2][l++]=workstat.getC10();
c[l2][l++]=workstat.getC11();
c[l2][l++]=workstat.getC12();
c[l2][l++]=workstat.getC13();
c[l2][l++]=workstat.getC14();
c[l2][l++]=workstat.getC15();
c[l2][l++]=workstat.getC16();
c[l2][l++]=workstat.getC17();
c[l2][l++]=workstat.getC18();
c[l2][l++]=workstat.getC19();
l2++;
}
int c2[][]=new int[m][i];
for(int l=0;l<17;l++){
for(l2=0;l2<m;l2++){
c2[0][l]=c2[0][l]+c[l2][l];
}
}
int b[]=new int[4];
b[0]=c2[0][0]+c2[0][1]+c2[0][2];
WorkStat workstat=new WorkStat();
workstat.setC1(b[0]);
workstat.setC2(c2[0][0]);
workstat.setC3(c2[0][1]);
workstat.setC4(c2[0][2]);
workstat.setC5(c2[0][3]);
workstat.setC6(c2[0][4]);
workstat.setC7(c2[0][5]);
workstat.setC8(c2[0][6]);
workstat.setC9(c2[0][7]);
workstat.setC10(c2[0][8]);
workstat.setC11(c2[0][9]);
workstat.setC12(c2[0][10]);
workstat.setC13(c2[0][11]);
workstat.setC14(c2[0][12]);
workstat.setC15(c2[0][13]);
workstat.setC16(c2[0][14]);
workstat.setC17(c2[0][15]);
workstat.setC18(c2[0][16]);
workstat.setC19(c2[0][17]);
listCount.add(workstat);
break;
}
return listCount;
}
}
<td> <s:property value="deptLevel+1" /> </td>
如果deptLevel是整形,原来的值是10,那么输出11;
如果deptLevel是字符串类型,原来的值是10,那么输出101; 想实现数字的格式化,参考下面的文章http://sys53.javaeye.com/blog/97433