trying to use this jstl to formulate a json string, how can i make the segment not to put a comma in the end of the last record? note the comma in the end
<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>
Just use 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>
You can also use the conditional operator in EL instead of <c:if>
:
${!loop.last ? ',' : ''}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With