我的目标是创建一个名为
的变量"Dollar Diff" = Value of posting.dollarsInHeader -posting.dollarsReceived)/1000000
检查下面的代码
<c:choose>
<c:when test="${posting.dollarsInHeader != 0 || posting.dollarsReceived != 0}">
<td class="alignright" class="${posting.dollarsInHeader < 0 || posting.dollarsReceived < 0 ? 'fontRed' : ''}">
<fmt:formatNumber type="currency" minFractionDigits="1"
maxFractionDigits="1">${(posting.dollarsInHeader - posting.dollarsReceived)/1000000}
</td>
</c:when>
<c:otherwise>
<td style="text-align: right; padding-right: 10px;">-</td>
</c:otherwise>
</c:choose>
我要写${(posting.dollarsInHeader - posting.dollarsReceived)/1000000}
而不是${dollarDiff}
答案 0 :(得分:2)
我不建议在视图层(jsp)中编写这样的逻辑。 您可以在发布类中添加一个字段,并相应地写回值。
//Ommit Posting class declaration
public double getDollarDiff(){
return (this.dollarsInHeader-this.dollarsReceived)/1000000;
}
然后简单地用以下内容引用它:
${posting.dollarDiff}
EL如果您的方法遵循getter约定,则将其视为字段。
但是,如果您不想修改pojo,可以尝试使用
<c:set scope="request" var="dollarDiff" value="${(posting.dollarsInHeader - posting.dollarsReceived)/1000000}"></c:set>
然后通过以下方式引用它:
<c:out value="${requestScope.dollarDiff}"></c:out>
<!--or-->
${requestScope.dollarDiff}