Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
JSTL and EL expressions for implementation of the Java double loop
1, the introduction of two jstl tag library in jsp page
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
2, Maven project to add jar package dependencies, packages and standard packages need jstl
<!-- https://mvnrepository.com/artifact/taglibs/standard -->
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
3, in a custom array jsp
<%
String[][] str3 = {{"李白1","杜甫1","白居易1"},{"李白2","杜甫2","白居易2"},{"李白3","杜甫3","白居易3"}};
application.setAttribute("str3", str3);
%>
4, a dual <c: foreach> tag iterate
<c:forEach var="i" begin="0" end="${fn:length(array)-1 }">
<c:forEach var="j" begin="0" end="${fn:length(array[i])-1 }">
${array[i][j] }
</c:forEach>
</c:forEach>
Screenshot results:
5, fn labels do not need to traverse the List
<%
List<String> list = new ArrayList<String>();
list.add("功夫大师");
list.add("圆明园");
list.add("景福宫");
request.setAttribute("list", list);
%>
Screenshot results: