• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EL expression question. Getting a value from a map that use Integer like key

 
Yeray Santana Borges
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, this is my code in my Servlet:


And I would like get the "mapValue 0" in the map1 attribute on my result.jsp using EL, but i can't get it
JSP code:


What is wrong??, I don't know how can I get a value from a map that use Integer keys using EL. If my map uses a String like key, I get the correct value. I think that is because in this EL expression, ${map1["0"]}, it is using "0" like a String, and map1.containsKey("0") is false.

How can I get it with EL?

Thanks
 
Lee Kian Giap
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you try this by changing your code to

Map<Long, String> map1 = new HashMap<Long,String>();
map1.put(0, "mapValue 0");
map1.put(1, "mapValue 1");
map1.put(2, "mapValue 2");

and get the value from EL using

${map1[0]}
${map1[1]}
${map1[2]}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic