Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need Tips for JSP EL

 
Hanuma Deepak Muvvala
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can any one tell the tips for JSP Expression Language, I got confused of using [] and . I am losingmarks in this area in mock up exams.

Thanks In Advance,
Deepak........
 
Mirko Bonasorte
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
only one thing: is more specific than : you can use the first one in place of the second one, but the opposite is not true.
 
Hanuma Deepak Muvvala
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You Mirko
 
Atul Sawant
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One huge gotcha for me was...

using quotes "" in [] while using map or bean attribute

For a key of a map or a property of a bean attribute you have to use "" quotes in the [] eg: ${bean["property"]} or ${map["key"]}. Only instance where you CAN use no quotes is when you store the key (if its a map) in an attribute or property (if its a bean) in an attribute.

For eg:

String property = beanclass.getProperty();

request.setAttribute("example", property) and then

${bean[example]} <-- see no "" quotes used.

2nd eg:

Map abc = new HashMap();
abc.put(key, "whatever");

request.setAttribute("example2", key) and access the map's key by

${map[example2]} <<- again no "" quotes used here

using ${bean[property]} or ${map[key]} is not correct because i have not used quotes.



incase of lists and arrays you can use quotes or no quotes in []...

eg: ${array[1]} or ${array["1"]} both are correct.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic