我有这个实际工作的代码:
<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 ?
我试过:
<c:forEach items="${breadcrumb.links}" var="link">
<s:url action='${link.url}' var="url" />
<li>
<a href="${url}">${link.name}</a>
</li>
</c:forEach>
但我收到错误:
According to TLD or attribute directive in tag file, attribute action does not accept any expressions
谢谢你。
最佳答案
为了更适应 Struts2 标签和 OGNL 语言,read and bookmark this answer .
由于 Struts2 标签仅评估 OGNL 表达式( and not EL Expression ,正如您的错误明确指出的那样),您需要通过 PageContext 属性(在 OGNL #attr.something
中)使用 var
指定来访问 JSTL 对象。 :
<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 Basics :
#attr['foo']
or#attr.foo
: Access toPageContext
if available, otherwise searchesrequest
/session
/application
respectively
关于jsp - 如何使用 JSTL <c :forEach> with Struts2 <s:url>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20457431/