var不能和items一样
再第一次遍历后list被改变了
所以后俩次没有值[HTML] 纯文本查看 复制代码 <%
String list[]={"111","222","333"};
pageContext.setAttribute("list", list);
%>
<h3>
<c:forEach var="list" items="${list }">
${list }
</c:forEach>
</h3>
<h3>
<c:forEach var="list" items="${list }">
${list }
</c:forEach>
</h3>
<h3>
<c:forEach var="list1" items="${list }">
${list1 }
</c:forEach>
</h3>
结果为
[HTML] 纯文本查看 复制代码 <body>
<h3>
111
222
333
</h3>
<h3>
</h3>
<h3>
</h3>
</body>
更改forEach的var名字
[HTML] 纯文本查看 复制代码 <%
String list[]={"111","222","333"};
pageContext.setAttribute("list", list);
%>
<h3>
<c:forEach var="l1" items="${list }">
${l1 }
</c:forEach>
</h3>
<h3>
<c:forEach var="l2" items="${list }">
${l2 }
</c:forEach>
</h3>
<h3>
<c:forEach var="l1" items="${list }">
${l1 }
</c:forEach>
</h3>
结果为
[HTML] 纯文本查看 复制代码 <body>
<h3>
111
222
333
</h3>
<h3>
111
222
333
</h3>
<h3>
111
222
333
</h3>
</body>
|