“$ {foo.bar}”和“#{foo.bar}”之间的区别是什么?

时间:2020-12-19 22:28:13

I can use objects from my Java Beans within .jsp files by using the Expression Language (EL). Therefore I can get my value by typing ${foo.bar}. But I can also use #{foo.bar}.

我可以使用表达式语言(EL)在.jsp文件中使用Java Beans中的对象。因此,我可以输入$ {foo.bar}来获取我的价值。但我也可以使用#{foo.bar}。

Can anybody explain the difference or provide a link with meaningful information?

任何人都可以解释这些差异或提供有意义的信息链接吗?

2 个解决方案

#1


6  

#{foo.bar} syntax is from the JSF expression language. Some bright spark thought it would be a good idea to use a different syntax to JSP EL (i.e. ${foo.bar}). I think some JSP containers are tolerant of this cockup, and let you use either one.

#{foo.bar}语法来自JSF表达式语言。一些明亮的火花认为使用与JSP EL不同的语法(即$ {foo.bar})是个好主意。我认为一些JSP容器可以容忍这个cockup,让你使用其中任何一个。

#2


17  

This is covered in the JSP 2.1 spec.

这在JSP 2.1规范中有所涉及。

In Java EE, #{expr} is used for deferred evaluation and ${expr} for immediate evaluation. Deferred expressions (#{expr}) expressions can only be used with tag attributes that accept them. This is a Java EE convention, but other domains could impose their own meaning (e.g. if you wanted to use EL in your own templates).

在Java EE中,#{expr}用于延迟评估,$ {expr}用于即时评估。延迟表达式(#{expr})表达式只能与接受它们的标记属性一起使用。这是一个Java EE约定,但其他域可以强加其自己的含义(例如,如果您想在自己的模板中使用EL)。

#1


6  

#{foo.bar} syntax is from the JSF expression language. Some bright spark thought it would be a good idea to use a different syntax to JSP EL (i.e. ${foo.bar}). I think some JSP containers are tolerant of this cockup, and let you use either one.

#{foo.bar}语法来自JSF表达式语言。一些明亮的火花认为使用与JSP EL不同的语法(即$ {foo.bar})是个好主意。我认为一些JSP容器可以容忍这个cockup,让你使用其中任何一个。

#2


17  

This is covered in the JSP 2.1 spec.

这在JSP 2.1规范中有所涉及。

In Java EE, #{expr} is used for deferred evaluation and ${expr} for immediate evaluation. Deferred expressions (#{expr}) expressions can only be used with tag attributes that accept them. This is a Java EE convention, but other domains could impose their own meaning (e.g. if you wanted to use EL in your own templates).

在Java EE中,#{expr}用于延迟评估,$ {expr}用于即时评估。延迟表达式(#{expr})表达式只能与接受它们的标记属性一起使用。这是一个Java EE约定,但其他域可以强加其自己的含义(例如,如果您想在自己的模板中使用EL)。