• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]}
 
Hang a left on main. Then read this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic