尝试使用这个jstl来形成一个json字符串,我怎样才能使这个段不在最后一条记录的末尾放一个逗号?注意末尾的逗号
<c:forEach items="${fileList}" var="current">
{ id:1001,data:["<c:out value="${current.fileName}" />" , "<c:out value="${current.path}" />" , "<c:out value="${current.size}" />" , "<c:out value="${current.type}" />"] },
</c:forEach>
发布于 2010-06-23 19:58:55
只需使用LoopTagStatus#isLast()
即可。
<c:forEach items="${fileList}" var="current" varStatus="loop">
{ id: 1001,
data: [
"<c:out value="${current.fileName}" />",
"<c:out value="${current.path}" />",
"<c:out value="${current.size}" />",
"<c:out value="${current.type}" />"
]
}<c:if test="${!loop.last}">,</c:if>
</c:forEach>
还可以在EL中使用条件运算符,而不是<c:if>
${!loop.last ? ',' : ''}
发布于 2010-06-23 15:18:33
在Check a collection size with JSTL中,答案是使用函数标签
将此内容放在页面顶部以允许使用fn名称空间
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
并在jsp页面中像这样使用。
<p>The length of the companies collection is : ${fn:length(companies)}</p>
https://stackoverflow.com/questions/3099234
复制相似问题