Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Working of Expression language

omkar patkar
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am using Tomcat 5.5 and Servlet 2.4 specification. I am learning J2EE basics from a book, "Pro JSP" from Apress edition. In this book, an example is given, which i am wondering it works ?

The example is as follows: -

The authors want to say that, if in an EL expression you want to include "$" and "{" need to escape it, and the example they gave is :-

In order to print = ${2 + 3} on the page...
the EL must be = ${'${'}2 + 3}

I am not able to understand how does the EL suggested in the book works does display the output as desired....but how ? ... Because, before reading the EL mentioned by the authors, i was thinking, how i would have written an EL to print "${2 + 3}" on page!

I came up with following EL expressions which also give the same desired result: -

EL expression no. 1)

... here i have escaped the characters in the order they will appear from Left to Right in the String literal

EL expression no. 2)
${"${2 + 3}"}
... here in this EL, i thought since, i just want to PRINT text ....that is string literal on the page,...why not put all the characters in double quotes ? all the three expression works....but how do they work ?...what is the exact processing done behind the scenes ? Which one is more correct and appropriate ?
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic