如何使用JSTL< c:forEach>与Struts2< s:url>? [英] How to use JSTL <c:forEach> with Struts2 <s:url>?

查看:118
本文介绍了如何使用JSTL< c:forEach>与Struts2< s:url>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码实际上有效:

<s:iterator value="breadcrumb.links" var="link">
    <s:url action='%{#link.url}' var="url" />
    <li>
       <a href="${url}">${link.name}</a>
    </li>
</s:iterator>

我怎么做同样的事情,但用c:foreach而不是s:iterator?

How con I do the same thing but with c:foreach instead of s:iterator ?

我试过:

<c:forEach items="${breadcrumb.links}" var="link">
    <s:url action='${link.url}' var="url" />
    <li>
        <a href="${url}">${link.name}</a>
    </li>
</c:forEach>

但我收到错误:


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

According to TLD or attribute directive in tag file, attribute action does not accept any expressions

谢谢你。

推荐答案

为了更加熟悉Struts2标签和OGNL语言,读取并为此答案添加书签

To be more comfortable with Struts2 tags and OGNL language, read and bookmark this answer.

由于Struts2标记仅评估OGNL表达式(而不是EL表达式 ,当您错误明确指出)时,您需要通过使用 var <指定的PageContext属性(在OGNL #attr.something 中)访问JSTL对象/ code>:

Since Struts2 tags only evaluate OGNL expressions (and not EL Expression, as you error clearly states), you need to access the JSTL object through the PageContext attribute (in OGNL #attr.something) specified with var :

<c:forEach items="${breadcrumb.links}" var="link">
    <s:url action='%{#attr.link.url}' var="url" />
    <li>
        <a href="${url}">${link.name}</a>
    </li>
</c:forEach>

来自 OGNL基础知识


#attr ['foo'] #attr.foo
:访问 PageContext 如果可用,否则搜索
request / session / application 分别

#attr['foo'] or #attr.foo : Access to PageContext if available, otherwise searches request/session/application respectively

这篇关于如何使用JSTL&lt; c:forEach&gt;与Struts2&lt; s:url&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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