java – 从EL执行和对象的方法
发布时间:2020-12-15 00:50:34 所属栏目:Java 来源:网络整理
导读:如何从EL调用对象的方法? 给对象: public class TestObj { public testObj() { }; public String test() { return "foo"; } public String someOtherMethod(String param) { return param + "_bar"; } } 并将obj添加到pageContext中 pageContext.setAttrib
如何从EL调用对象的方法?
给对象: public class TestObj { public testObj() { }; public String test() { return "foo"; } public String someOtherMethod(String param) { return param + "_bar"; } } 并将obj添加到pageContext中 pageContext.setAttribute("t",new TestObj()); 我将如何执行相当于: <%= t.test() %> <%= t.someOtherMethod("foo") %> 使用EL? 解决方法
自从2009年12月10日(已超过2.5年前)已经推出的EL 2.2以来,它得到了支持. EL 2.2与Servlet 3.0密切相关,因此如果您使用Servlet 3.0兼容的web.xml定位Servlet 3.0容器(
Tomcat 7,Glassfish 3等),如下所示
<?xml version="1.0" encoding="UTF-8"?> <web-app 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-app_3_0.xsd" version="3.0"> <!-- Config here. --> </web-app> 那么你将能够以下列形式在EL中调用带或不带参数的方法: ${t.test()} ${t.someOtherMethod('foo')} (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容