Whats the difference between “${foo.bar}” and “#{foo.bar}”?

落花浮王杯 提交于 2019-12-19 09:06:05

问题


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}.

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


回答1:


#{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.




回答2:


This is covered in the JSP 2.1 spec.

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).



来源:https://stackoverflow.com/questions/1311425/whats-the-difference-between-foo-bar-and-foo-bar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!