Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • 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
  • 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
  • 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]}
 
There is no "i" in denial. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic