
你不能直接在EL中调用静态方法。EL将仅调用实例方法。
对于失败的scriptlet尝试,你不能混合scriptlet和EL。使用一个或另一个。由于小脚本被劝阻了十多年,你应该坚持的EL-唯一的解决办法。
你基本上有2个选择(假设
balance和
Calculate#getAmount()均为
double)。
- 只需将其包装在实例方法中即可。
public double getAmount() { return Calculate.getAmount(balance);}并改用它:
Amount: ${row.amount}- 或者,声明Calculate#getAmount()为EL函数。首先创建一个/WEB-INF/functions.tld文件:
<?xml version="1.0" encoding="UTF-8" ?><taglib 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"> <display-name>Custom Functions</display-name> <tlib-version>1.0</tlib-version> <uri>http://example.com/functions</uri> <function> <name>calculateAmount</name> <function-class>com.example.Calculate</function-class> <function-signature>double getAmount(double)</function-signature> </function></taglib>
并按如下所示使用它:
<%@taglib uri="http://example.com/functions" prefix="f" %>...Amount: ${f:calculateAmount(row.balance)}">欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)