您不能混合scriptlet和EL。使用一个或另一个。由于脚本在十年内不鼓励,你应该去EL。
你基本上有两个选项(假设两者的平衡和计算#getAmount()是双)。
>只需添加另一个getter。
public double getAmount() {
return Calculate.getAmount(balance);
}
并改用它:
Amount: ${row.amount}
>或者,将Calculate#getAmount()声明为EL函数。首先创建一个/WEB-INF/functions.tld文件:
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
version="2.1">
Custom Functions
1.0
http://example.com/functions
calculateAmount
com.example.Calculate
double getAmount(double)
并使用它如下:
...
Amount: ${f:calculateAmount(row.balance)}">