1.两层循环
{税种1,{[a,b,c,d,e],[a,b,c,d,e],[a,b,c,d,e[a,b,c,d,e]}}
{税种2,{[a,b,c,d,e],[a,b,c,d,e],[a,b,c,d,e[a,b,c,d,e]}}
test.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <body> <% List list = new ArrayList(); String[] arr1 = new String[] { "a", "b", "c", "d", "e" }; String[] arr2 = new String[] { "a", "b", "c", "d", "e" }; String[] arr3 = new String[] { "a", "b", "c", "d", "e" }; String[] arr4 = new String[] { "a", "b", "c", "d", "e" }; list.add(arr1); list.add(arr2); list.add(arr3); list.add(arr4); List lista = new ArrayList(); lista.add("税种"); lista.add(list); List list1 = new ArrayList(); String[] arr11 = new String[] { "a", "b", "c", "d", "e" }; String[] arr22 = new String[] { "a", "b", "c", "d", "e" }; String[] arr33 = new String[] { "a", "b", "c", "d", "e" }; String[] arr44 = new String[] { "a", "b", "c", "d", "e" }; String[] arr55 = new String[] { "a", "b", "c", "d", "e" }; list1.add(arr11); list1.add(arr22); list1.add(arr33); list1.add(arr44); list1.add(arr55); List listb = new ArrayList(); listb.add("税种"); listb.add(list1); List listc = new ArrayList(); listc.add(lista); listc.add(listb); request.setAttribute("listc", listc); %> <table border="1" bordercolor="red" style="margin: 0;padding: 0"> <tr> <td>税种</td> <td>金额</td> <td>金额</td> <td>金额</td> <td>金额</td> <td>金额</td> </tr> <c:forEach items="${listc}" var="subList1"> <tr> <td rowspan="${fn:length(subList1[1])}">${subList1[0]}</td> <c:forEach items="${subList1[1]}" var="subList2" varStatus="status1"> <c:if test="${status1.index==0}"> <c:forEach items="${subList2}" var="subList3" varStatus="status2"> <td>${subList3}</td> </c:forEach> </tr> </c:if> <c:if test="${status1.index>0}"> <tr> <c:forEach items="${subList2}" var="subList3" varStatus="status2"> <td>${subList3}</td> </c:forEach> </tr> </c:if> </c:forEach> </c:forEach> </table> </body> </html>
2.三层循环:
{
{名称,
{税种1,{[a,b,c,d,e],[a,b,c,d,e],[a,b,c,d,e[a,b,c,d,e]}},
{税种2,{[a,b,c,d,e],[a,b,c,d,e],[a,b,c,d,e],[a,b,c,d,e],[a,b,c,d,e]}}
}
,
{名称,
{税种1,{[a,b,c,d,e],[a,b,c,d,e],[a,b,c,d,e[a,b,c,d,e]}},
{税种2,{[a,b,c,d,e],[a,b,c,d,e],[a,b,c,d,e],[a,b,c,d,e],[a,b,c,d,e]}},
{税种2,{[a,b,c,d,e],[a,b,c,d,e],[a,b,c,d,e],[a,b,c,d,e],[a,b,c,d,e]}}
}
}
test.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <body> <% List list = new ArrayList(); String[] arr1 = new String[] { "a", "b", "c", "d", "e" }; String[] arr2 = new String[] { "a", "b", "c", "d", "e" }; String[] arr3 = new String[] { "a", "b", "c", "d", "e" }; String[] arr4 = new String[] { "a", "b", "c", "d", "e" }; list.add(arr1); list.add(arr2); list.add(arr3); list.add(arr4); List lista = new ArrayList(); lista.add("增值税-进项"); lista.add(list); List list1 = new ArrayList(); String[] arr11 = new String[] { "a", "b", "c", "d", "e" }; String[] arr22 = new String[] { "a", "b", "c", "d", "e" }; String[] arr33 = new String[] { "a", "b", "c", "d", "e" }; String[] arr44 = new String[] { "a", "b", "c", "d", "e" }; String[] arr55 = new String[] { "a", "b", "c", "d", "e" }; list1.add(arr11); list1.add(arr22); list1.add(arr33); list1.add(arr44); list1.add(arr55); List listb = new ArrayList(); listb.add("增值税-销项"); listb.add(list1); List listc = new ArrayList(); listc.add("增值税"); listc.add(lista); listc.add(listb); List listd = new ArrayList(); listd.add(listc); //listd.add(listc); request.setAttribute("listf", listd); %> <table border="1" bordercolor="red" style="margin: 0;padding: 0"> <tr> <td>名称</td> <td>税种</td> <td>金额</td> <td>金额</td> <td>金额</td> <td>金额</td> <td>金额</td> </tr> <!-- first loop --> <c:forEach items="${listf}" var="subList1" > <!-- get firstRowSpan --> <c:set var="firstRowSpan" value="0"></c:set> <c:forEach items="${subList1}" var="subList11" varStatus="s11"> <c:if test="${s11.index>0}"> <c:set var="firstRowSpan" value="${fn:length(subList11[1])+firstRowSpan}"></c:set> </c:if> </c:forEach> <!-- second loop --> <c:forEach items="${subList1}" var="subList2" varStatus="s1"> <c:if test="${s1.index==0}"> <tr> <td rowspan="${firstRowSpan}">${subList1[0]}:rowspan:${firstRowSpan}</td> </c:if> <c:if test="${s1.index>0}"> <c:forEach items="${subList2}" var="subList22" varStatus="s22"> <c:if test="${s22.index==0}"> <td rowspan="${fn:length(subList2[1])}">${subList2[0]}:rowspan:${fn:length(subList2[1])}</td> </c:if> <c:if test="${s22.index>0}"> <c:forEach items="${subList22}" var="subList33" varStatus="s33" > <c:if test="${s22.index==1}"> <c:forEach items="${subList33}" var="subList44" varStatus="s44" > <td>${subList44}</td> </c:forEach> </tr> </c:if> <c:if test="${s22.index>1}"> <tr> <c:forEach items="${subList33}" var="subList44" varStatus="s44" > <td>${subList44}</td> </c:forEach> </tr> </c:if> </c:forEach> </c:if> </c:forEach> </c:if> </c:forEach> <!-- second loop --> </c:forEach> <!-- first loop --> </table> 第一个单元格的rowSpan为:${firstLayerSpan} </body> </html>