grails 是否支持使用“forEach”?来自 gsp 页面中的 JSTL 核心标签库?
我在使用 grails 编写 gsp 页面时遇到问题。该页面可以与 JSTL 核心标签库中的其他标签(例如 c:if、c:when)配合使用。但是当我使用 c:forEach 进行循环时,我无法让它工作。以下是代码片段:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
......
<c:forEach var="foo" items="${fooList}" varStatus="counter">
${counter.count}, ${foo}
</c:forEach>
Grails 的错误表明隐式对象计数器为空。
Error 500: null
Servlet:
URI:
Exception Message: Cannot get property 'count' on null object
Caused by: Error evaluating expression [counter.count] on line [16]: Cannot get property 'count' on null object
从Grails文档来看,据说支持JSP标签。
==>> “http://grails.org/doc/latest/guide/6.%20The%20Web%20Layer.html#6.3.6 使用 JSP 标签库”
但我就是无法让 c:forEach 工作,它工作得很好jsp 页面而不是带有 gsp 后缀。
Grails 版本:1.37 JDK:1.6.0_22
I had the problem in writing the gsp page using grails. The page works fine with other tags from JSTL core taglib, such as c:if, c:when. But I could not get it work when I was using c:forEach for looping. Following are the code snippets:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
......
<c:forEach var="foo" items="${fooList}" varStatus="counter">
${counter.count}, ${foo}
</c:forEach>
The errors from Grails shows that the implicit object counter is null.
Error 500: null
Servlet:
URI:
Exception Message: Cannot get property 'count' on null object
Caused by: Error evaluating expression [counter.count] on line [16]: Cannot get property 'count' on null object
From the Grails documentation, it is said that JSP tags are supported.
==>> "http://grails.org/doc/latest/guide/6.%20The%20Web%20Layer.html#6.3.6 Using JSP Tag Libraries"
But I just could not get c:forEach to work, which works fine as a jsp page instead of having a gsp suffix.
Grails Version: 1.37
JDK: 1.6.0_22
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最好对以下各项使用标准 GSP:
It's much better to use standard GSP's for each:
试试这个:
我遇到了同样的问题......
然后我发现是 ${counter} 而不是 ${counter.count} 来显示商品编号。
Try this instead:
I was having the same problem...
Then I figured out that it was ${counter} instead of ${counter.count} to get the item number to show up.