File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes ${} vs %{} vs #{}? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "${} vs %{} vs #{}?" Watch "${} vs %{} vs #{}?" New topic

${} vs %{} vs #{}?

Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
I remember reading that $ is immediate evaluation and % is lazy evaluation in EL but i might've been confused somehow, i can't find a link back to that.
Anyway they both work in EL. Then there's the #{} that is OGNL and throws this in EL:
org.apache.jasper.JasperException: /index.jsp(14,38) #{..} is not allowed in template text

P.S. ${} and %{} both work in JSP.
Ankit Garg

Joined: Aug 03, 2008
Posts: 9466

P.S. ${} and %{} both work in JSP

Are you sure?? ${} is EL %{} is not. %{} is part of the OGNL syntax which is used to get values from the default object of the ActionContext (the default is the ValueStack i.e. %{} by default gets values from the ValueStack). %{} can be used with # i.e. %{# } is used to get a value from the ActionContext itself. The ActionContext contains the attributes of different scopes so if you write %{#session['attr']} , the value of the session scoped attribute named attr is returned...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
I think i get the difference, i might've mistaken and tried %{} in a struts 2 enabled envirnoment. In a simple HelloWorld JSP app %{} doesn't work (not EL). Thanks.
I agree. Here's the link:
subject: ${} vs %{} vs #{}?
It's not a secret anymore!