Was wondering if it’s possible to remove the last item from an array using JSTL? Currently I’m using c:url to append parameters (from an array) to a hyperlink. I want to be able to remove the last parameter as well…
Here is the code for the c:url to append parameters
<c:url value="search" var="url">
<c:param name="q" value="${q}"/>
<c:forEach var="field" items="${fq}">
<c:param name="fq" value="${field}"/>
</c:forEach>
</c:url>
No, that’s not possible. You can’t manipulate arrays in JSTL. You can at highest set the last item to
null, but that won’t change the array’s length.In your particular case there’s however another way: you can check if you’re currently iterating over the last array item by checking
LoopTagStatus#isLast()and then just skip the item altogether in<c:param>Note that I removed the
fn:length()check because that’s unnecessary. The<c:forEach>already won’t iterate if there are no items.