I can access a HashMap<String, Object> easily enough in JSTL but is it possible to access a HashMap<Object, Object>
I only ask because I don’t receive any errors (or output) when trying the following:
${myHashMap[anObject]}
It leads me to believe that myHashMap is trying to find my value but it is somehow not evaluating anObject as the correct key. I can verify that myHashMap has anObject as a key with a (non-blank/non-null) value that should display.
This syntax ought indeed to work. I understand that you didn’t get any value by the given object as key although you’re confident that the desired object is in there? In that case, the class as represented behind
${anObject}in your code must have theequals()(andhashCode()) methods properly implemented. TheMap#get()namely tests the key byequals()method. See also the javadoc:In other words, if the
equals()of your${anObject}returnstruefor the map key, then the associated map value will be returned, otherwisenullwill be returned and EL will then print nothing.That it works for
Stringis simply because that class has theequals()already properly implemented.See also: