0

I've been hung up on this issue for a while now, and it's driving me insane.

I have a hash that looks like this in java:

hash.get("1") => "Hello"
hash.get("2") => "Hello"
hash.get("3") => "Hello"
hash.get("4") => "Hello"

This works in JSP to get "1":

${hash["1"]}

But this doesn't:

<c:forEach begin='1' end='4' var='index'>
    ${index}
    ${hash[index]}
</c:forEach>

Why can't I access an element in a hash in JSP by a variable's alias? I can use a foreach loop on the hash, but I don't want to do that. Is it possible, at all, to just access a hash element by a variable-aliased key?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Waffles
  • 349
  • 1
  • 8
  • 19

1 Answers1

0

Got it:

 <c:set var="stringId">${index}</c:set>
 ${ratingsCount[stringId]}

Source: Convert integer value to string using JSTL/EL

Community
  • 1
  • 1
Waffles
  • 349
  • 1
  • 8
  • 19
  • In name of our cc-by-sa license, it would be fair if you cited/linked the [source](http://stackoverflow.com/questions/3576131/convert-integer-value-to-string-using-jstl-el/3576485#3576485) where you found this answer. – BalusC Aug 13 '15 at 21:49
  • Sorry, linked source. – Waffles Aug 18 '15 at 23:21