【问题标题】:How to use foreach in struts如何在struts中使用foreach
【发布时间】:2011-12-08 05:57:09
【问题描述】:

我在使用 forEach 的地方有这个 struts 代码-

<c:forEach items="${reviewList}" var="reviewListId">
<tr>
   <td colspan="6" class="we_have"><c:out value="${reviewListId}" />
   </td>
</tr>

我已经添加了这个标签库

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

但是代替forEach标签显示的错误是-

根据标签文件中的TLD或属性指令,属性项不接受任何表达式

但是代替标签库它没有显示任何错误,这意味着它支持这个标签库但不知道为什么它不支持forEach标签。

【问题讨论】:

  • 您使用的是哪个服务器和服务器版本。似乎 JSTL 命名空间是错误的。
  • 为什么你没有使用逻辑:迭代标签。是Struts自己提供的?

标签: java foreach struts


【解决方案1】:

试试&lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core prefix="c"%&gt;

【讨论】:

【解决方案2】:

如果没有看到代码,我不知道更多关于这个问题的信息,但如果它不起作用,那么您可以使用的另一个替代方法是 struts Iterator

Iterator will iterate over a value. An iterable value can be any of: java.util.Collection, java.util.Iterator

http://struts.apache.org/2.0.14/docs/iterator.html

【讨论】:

  • 似乎这是struts2的例子,但我使用的是struts1。
  • 但是我们有一个类,其中有 4 个字段可用,我们想在不同的列中显示这些所有字段,所以我们使用 forEach,因为它不可能在迭代中。
  • 就是这样的列表——customer cust=new customer(); cust.setName("名称"); cust.setLastName("姓氏");和 reviewList.add(cust);所以我想在两个差异列中显示这两个字段。表示这是 Pojo 列表。
  • reviewList 是客户对象的列表,因此您可以将其用作 name name ,....
【解决方案3】:

请验证您的 c.tld 项目属性是否允许 rtexprvalue,

    <attribute>
        <name>items</name>
        <required>false</required>
        <rtexprvalue>false</rtexprvalue>
    </attribute>

这是错误的,如果这样的声明你不能表达。请更改 rtexprvalue true 并尝试。最好下载正确版本的 tld 文件

【讨论】:

猜你喜欢
  • 2014-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多