Use <c:set> to initialize the shared variable, use <c:forEach> to iterate over the list, and use another <c:set> to add the iterated value to the final value.
<c:set var="total" value="${0}"/> <c:forEach var="article" items="${list}"> <c:set var="total" value="${total + article.price}" /> </c:forEach>
See also Iterate over list and map elements using the JSTL <c: forEach> tag .
source share