Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I use arithmetic operators with struts tags

Status
Not open for further replies.

liorza

Programmer
Mar 3, 2004
27
0
0
US
Hello,
I am having some issues with jstl tags. I would like to do basic math operations on values in struts tags (bean:write ...)

Any ideas?

Lior
 
Hi

Do you mean like in this JSP fragment ?
Code:
[blue]<%@taglib uri="[URL unfurl="true"]http://java.sun.com/jsp/jstl/core"[/URL] prefix="c"%>[/blue]

[gray]<!-- ... -->[/gray]

<table>
<tr>
  <th>Product</th>
  <th>Quantity</th>
  <th>Price</th>
  <th>Value</th>
</tr>
[blue]<c:set var="total" value="0"/>[/blue]
[blue]<c:forEach var="prod" items="[green]${sessionScope.cart}[/green]">[/blue]
  [blue]<c:set var="total" value="[green]${total+prod.value.quantity*prod.value.price}[/green]"/>[/blue]
  <tr>
    <td>[green]${prod.value.name}[/green]</td>
    <td>[green]${prod.value.quantity}[/green]</td>
    <td>[green]${prod.value.price}[/green]</td>
    <td>[green]${prod.value.quantity*prod.value.price}[/green]</td>
  </tr>
[blue]</c:forEach>[/blue]
</table>

<table>
<tr>
  <th>Total</th>
  <td>[blue]<c:out value="[green]${total}[/green]"/>[/blue] $</td>
</tr>
<tr>
  <th>Bonus</th>
  <td>[green]${sessionScope.bonus}[/green] %</td>
</tr>
<tr>
  <th>Total - bonus %</th>
  <td>[green]${total*(1-sessionScope.bonus/100)}[/green] $</td>
</tr>
</table>

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top