EL:如何打印静态变量?
我有以下 JSP 页面:
<%@taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
test #1: value of PI is <c:out value="${java.lang.Math.PI}" />.
test #2: value of PI is ${java.lang.Math.PI}.
test #3: value of PI is <%= java.lang.Math.PI %>.
不知何故,只有测试 #3 有输出。为什么 EL 不打印静态变量的值?
I have the following JSP page:
<%@taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
test #1: value of PI is <c:out value="${java.lang.Math.PI}" />.
test #2: value of PI is ${java.lang.Math.PI}.
test #3: value of PI is <%= java.lang.Math.PI %>.
Somehow, only test #3 has output. why doesn't EL print out values of static variables?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于每个示例,正在发生的事情是这样的:
正在查找名为 java 的变量或 bean 并尝试在其上执行名为 lang 的方法。您的 JSP 页面中可能没有名为 Java 的变量或 bean,因此没有输出。
这与上面相同,只是仅使用 EL 编写。其相同之处在于它正在寻找名为 java 的变量或 bean。
这是在 JSP 编译期间,计算 java.lang.Math.PI 并将其写入 JSP 中。如果您查看编译后的 JSP,您将看到其中写入的值。
第三个示例是像在 Java 类中一样计算表达式。前两个示例期望“java”是变量名。
For each of your examples, this is what is happening:
This is looking for the variable or bean named java and trying to execute a method on it called lang. There is probably no variable or bean in your JSP page called Java so there is no output.
This is the same as above, just written using EL only. It's the same in that it's looking for a variable or bean named java.
What this is doing is during the JSP compile, java.lang.Math.PI is being calculated and written into the JSP. If you look at the compiled JSP you will see the value written there.
The third example is evaluating the expression as if you were in a Java class. The first two examples expect 'java' to be a variable name.