dictionaryjspstruts-1

How to access map values on the basis of keys in struts 1.x tags, not just iterate


I have a getter method in the bean associated with my form, which returns a Map. I want to access the object corresponding to a given String key from the map using Struts 1.x tags. I can iterate over the map by using its entry set and retrieve each key and its corresponding value, but I can't think of a way to access the value using directly its key


Solution

  • Just use

    ${bean.map.key}
    

    to get it. Or, if it is a dynamic key in flavor of another variable, use the brace notation

    ${bean.map[key]}
    

    this is also useful if the hardcoded key itself contains one or more periods

    ${bean.map['key.with.periods']}