简体   繁体   English

使用表达式语言调用 while 循环

[英]Invoke while loop with expression language

I have following while loop in my jsp file:我的jsp文件中有以下while循环:

<%
    List sorts = (List)request.getAttribute("sorts");
    Iterator it = sorts.iterator();
    while(it.hasNext()) {
        out.print(it.next());
}
%>

How can I avoid the Java Code in my JSP file here using Expression Language?如何在此处使用表达式语言避免 JSP 文件中的 Java 代码?

I've tried to save the it.next()) parameter in variables but it didnt work.我试图将it.next())参数保存在变量中,但没有用。

It is not possible to use while loop in expression language.instead of while you can use foreach loop.在表达式语言中不能使用 while 循环。您可以使用 foreach 循环代替 while。

syntax foreach loop is below- foreach 循环的语法如下-

<c:forEach var="name of scoped variable"
       items="Colleciton,List or Array" >

where c is prefix其中 c 是前缀

var is variable name where data store from collection. var 是变量名,数据存储在集合中。

items is collection or list.项目是集合或列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM