JSP EL表达式支持方法调用2011-08-06 BlogJava advincenting在JEE6中,JSP中的EL表达式支持带参数的方法调用了。可以像这样调用:${foo.bar(baz)} 。最新的实现是JUEL,大家可以下载试用一下。下面代码就是测试如何使用:// the ExpressionFactory implementation is de.odysseus.el.ExpressionFactoryImpl| System.setProperty("javax.el.methodInvocations", "true"); ExpressionFactory factory = new de.odysseus.el.ExpressionFactoryImpl (System.getProperties());
// package de.odysseus.el.util provides a ready-to-use subclass of ELContext de.odysseus.el.util.SimpleContext context = new de.odysseus.el.util.SimpleContext (); 07. // set value for top-level property "foo" to String value "bar" factory.createValueExpression(context, "${foo}", String.class).setValue(context, "bar");
// create an expression ValueExpression e = factory.createValueExpression(context, "${foo.toUpperCase()}", String.class); // evaluate System.out.println(e.getValue(context)); // --> BAR