使用表达式语言调用 while 循环
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 表达式中使用 while 循环 language.instead 而 while 可以使用 foreach 循环。
foreach 循环的语法如下-
<c:forEach var="name of scoped variable"
items="Colleciton,List or Array" >
其中 c 是前缀
var 是从集合中存储数据的变量名。
items 是集合或列表。
我的 jsp 文件中有以下 while 循环:
<%
List sorts = (List)request.getAttribute("sorts");
Iterator it = sorts.iterator();
while(it.hasNext()) {
out.print(it.next());
}
%>
如何使用表达式语言避免 JSP 文件中的 Java 代码?
我尝试将 it.next())
参数保存在变量中,但没有成功。
不能在 while 表达式中使用 while 循环 language.instead 而 while 可以使用 foreach 循环。
foreach 循环的语法如下-
<c:forEach var="name of scoped variable"
items="Colleciton,List or Array" >
其中 c 是前缀
var 是从集合中存储数据的变量名。
items 是集合或列表。