Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 用表达式语言调用while循环_Java_Html_Jsp_El - Fatal编程技术网

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

Java 用表达式语言调用while循环,java,html,jsp,el,Java,Html,Jsp,El,我的jsp文件中有以下while循环: <% List sorts = (List)request.getAttribute("sorts"); Iterator it = sorts.iterator(); while(it.hasNext()) { out.print(it.next()); } %> 如何使用表达式语言避免JSP文件中的Java代码 我已尝试将it.next())参数保存在变量中,但无效。无法在表达式语言中使用whi

我的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是从集合中存储数据的变量名


项是集合或列表。

您知道forEach循环是自动增量循环。无需使用作用域变量的名称定义下一个和访问值。