首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 網頁程式設計 >> JSP 程式設計 >> 關於JSP

JSP EL 表達式支援方法調用

     編輯:關於JSP

JEE 6 起,EL 表達式支援帶參數方法調用:${foo.bar(baz)}。參考實作 JUEL(de.odysseus.el.ExpressionFactoryImpl)。

測試代碼

System.setProperty("javax.el.methodInvocations", "true");
ExpressionFactory factory = new de.odysseus.el.ExpressionFactoryImpl(System.getProperties());
de.odysseus.el.util.SimpleContext context = new de.odysseus.el.util.SimpleContext();
factory.createValueExpression(context, "${foo}", String.class).setValue(context, "bar");
ValueExpression e = factory.createValueExpression(context, "${foo.toUpperCase()}", String.class);
System.out.println(e.getValue(context)); // 輸出 BAR

啟用 javax.el.methodInvocations=true 即可在 JSP 頁面中直接調用 Bean 方法,極大增強表達能力。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved