• Post Reply Bookmark Topic Watch Topic
  • New Topic

Expression Language

 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I have a following piece of code in my Servlet class


And here is my jsp



Why the above mentioned jsp runs successfully, and not this one?



Similarly,

works

but doesn't. Why?
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because it will try to find the value of an attribute (page context first, then request, then session, then servlet context) called Akon, and use that value as the index / key.
That's why the first example works the other way around - the map doesn't have a key "Genre", but there is an attribute called "Genre" with a value that is a valid key.
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That means, the variable in double quotes represents map key, and those without double quotes represents attribute. Am i right?
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. The main thing to remember - with the bracket notation, anything not in quotes is either a numeric literal (e.g. [0]), boolean literal (e.g. [true]), null or the name of an attribute.
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Rob
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!