[英]Invoke while loop with expression language
我的jsp文件中有以下while循環:
<%
List sorts = (List)request.getAttribute("sorts");
Iterator it = sorts.iterator();
while(it.hasNext()) {
out.print(it.next());
}
%>
如何在此處使用表達式語言避免 JSP 文件中的 Java 代碼?
我試圖將it.next())
參數保存在變量中,但沒有用。
在表達式語言中不能使用 while 循環。您可以使用 foreach 循環代替 while。
foreach 循環的語法如下-
<c:forEach var="name of scoped variable"
items="Colleciton,List or Array" >
其中 c 是前綴
var 是變量名,數據存儲在集合中。
項目是集合或列表。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.