el表达式调用方法(曾经碰到的一个问题)

来源:互联网 发布:数据粒度怎么计算 编辑:程序博客网 时间:2024/05/29 02:20

JDK 1.6.0_26

myEclipse 9

el这样

Java code
<td> ${log.operateType.name} </td>

此时,tomcat 7和myeclipse自带的tomcat下均没问题

而当

Java code
<td> ${log.operateType.getName()} </td>

此时,tomcat 7没问题,myeclipse自带tomcat报错

/WEB-INF/views/jsp/systemLog/logList.jsp(256,14) The function getName must be used with a prefix when a default namespace is not specified

为什么tomcat 7没问题而myeclipse自带的tomcat 会出现问题?

在 EL 中直接调用 method.
重點在於 tomcat 7 implements JSP EL 2.2
只要有 implements JSP EL 2.2 都可用此語法, 如 WebSphere v8.
不一定要使用 tomcat.

el 2.2
里面有这样一句话

In version 2.2, either type of EL expression can represent a method invocation, such as
${trader.buy(“JAVA”)}, where the arguments to the mothod invocation are specified in the expression

总结一下,在 EL 中直接呼叫 method 因为tomcat 7 对Servlet 3.0,JSP 2.2和JSP-EL 2.2的支持,el 2.2 支持调用方法  有什么不对或者不完善的地方请大家指正