How can I realise this with JSP and JSTL?
int total = 0;
for (Article article : list) {
total += article.price;
}
Use <c:set>
to initialize the total variable, use <c:forEach>
to iterate over list and use another <c:set>
to add the iterated value to the total.
<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 elements of List and Map using JSTL <c:forEach> tag.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments