<c:forEach var="a" items="${cart}">
<c:set var="total" value="0" scope="session"></c:set>
${total+=a.value.quantity*a.value.book.price}"
</c:forEach>
我想求的total的值,total集合的一个价格,集合遍历的同时,把总价求出来,放入session中..

解决方案 »

  1.   

    自己看着自己的帖子不沉,,题目中不能使用jsp
      

  2.   

    你要把a.value.quantity和a.value.book.price转换成int型才能相乘,EL取出来的都是String类型,包括你的<c:set>
      

  3.   

    <c:set var="total" value="0" scope="session"></c:set>
    <c:forEach var="a" items="${cart}">
    ${total+=a.value.quantity*a.value.book.price}
    <c:set var="total" value="${total+=a.value.quantity*a.value.book.price}" scope="session"></c:set>
    </c:forEach>注:quantity和price必须是数字类型属性。
      

  4.   

    org.apache.jasper.JasperException: /ch05/viewCart.jsp(81,8) "${total+=a.value.quantity*a.value.book.price}" contains invalid expression(s): javax.el.ELException: Error Parsing: ${total+=a.value.quantity*a.value.book.price
    报这样的错误,,,不行啊,求救