对于表达式语言的每个循环 [英] For each loop with Expression Language

查看:101
本文介绍了对于表达式语言的每个循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打印出我的列表中的每个项目,在JSP文件中使用表达式语言排序,如下所示:

I want to print out every Item of my list "sorts" with Expression Language in a JSP File like that:

Try: Pizza-Margherita
Try: Cheese-Pizza

像这样的正常表达式

So it works if i use a normal expression like this

Try: ${sorts[0]}
Try: ${sorts[1]}

但是我必须为列表中的每个项目写一个

But i have to write it for every Item in the List

所以我尝试使用以下两个循环:

So I tried to use following two Loops:

<c:forEach items="${sorts}" var="item">
   Try: ${item}<br>
</c:forEach>


<c:forEach var="item" items="${sorts}">
    <td>
       Try: <c:out value="${item}" />
    </td>
</c:forEach>

它没有用,我每次都得到这个输出:

It didn't work and I got this output each time:

Try:

为什么赢了'我的foreach循环工作?我做错了什么?

Why won't my foreach loop work? what have I done wrong?

推荐答案

这是因为您没有在JSP文件中包含核心标记库。
您将通过在文件顶部插入以下行来完成此操作。

It is because you haven't included the core tag library in your JSP file. You will do this by inserting following Line at the top of your file.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

这篇关于对于表达式语言的每个循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆