Question

I'm trying to multiply 2 numbers that come in variables related to an item that is inside a loop. Here is the code in the JSP:

<table>
    <thead>
        <tr>
            <th>PRICE</th>
            <th>AMOUNT</th>
            <th>SUBTOTAL</th>
        </tr>
    </thead>
    <tbody>
        <c:forEach items="${cesta._O_LID_PEDI}" var="item" varStatus="contador">
            <tr>
                <td>
                    <p>${item.PRICE}</p>
                </td>
                <td>
                    <p>${item.AMOUNT}</p>
                </td>
                <td>
                    <p>${item.PRICE} * ${item.AMOUNT}</p>
                </td>
            </tr>
        </c:forEach>
    </tbody>
</table>

The third column (SUBTOTAL) is the one I want to display the result of the operation in, instead of the operation itself.

basket is a session attribute (set from a Java servlet) that contains a list of PRODUCTS. Each product has 2 elements: PRICE and AMOUNT, and I want to display both elements aside the multiplication of them.

Was it helpful?

Solution

It should be:

<p>${item.PRICE * item.AMOUNT}</p>

The whole expression goes inside the ${ ... } part.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top