calculate in struts 2 tag?
I have an iterate and i want to calculate sum of the values like this :
<s:iterator value="myValues" status="myStatus">
<s:property value="value" />
</s:iterator&g开发者_Python百科t;
<s:property value="total.here" />
I want to show the sum of "value" in "total.here". Sorry for my bad english. Thank you very much.
Assuming myValues is an array or a list of integral values accessible from your action:
<s:set var="total" value="%{0}" />
<s:iterator value="myValues">
<s:set var="total" value="%{top + #attr.total}" />
</s:iterator>
<s:property value="%{'' + #attr.total}" />
Samuel_xL's answer is right. But, in general, if you can edit your action class, I'd advice to make the calculation there instead of doing it in jsp.
精彩评论