gpt4 book ai didi

java - JSTL中计算的jsp中访问JSTL变量

转载 作者:行者123 更新时间:2023-12-01 22:44:09 24 4
gpt4 key购买 nike

在jsp中我有这部分并且工作正常

<c:forEach var="info" items="${infoList}" >
<tr>
<td>${info.key} </td>
<td>${info.total}</td>
<td>${info.delay}</td>
</tr>
</c:forEach>

这里infoList来自 struts Action 类,它是 ArrayListInfo

public class Info{
private String key;
private String total;
private String delay

}

现在我需要添加另一个 <td>它将打印像 ${info.delay}*100/${info.total} 这样计算的百分比,但会打印小数点后精确两位数。

我试过了

${ info.totalDelay*100/info.totalShipment } 

打印百分比但不能限制为 2 位数字。在java中我可以使用

NumberFormat formatter = new DecimalFormat("#0.00");

但是我将如何做到这一点,因为在 <% %> (jap tag) 中我不能使用${}

我可以访问 <% %> 中的那些变量吗?或者我可以使用 formatter .format()<c:>标签

最佳答案

使用 JSTL Format Number

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<fmt:formatNumber type="number" minFractionDigits="2" maxFractionDigits="2" value="${ info.totalDelay*100/info.totalShipment } " />

关于java - JSTL中计算的jsp中访问JSTL变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25591194/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com