1

If I have some object stored as a request attribute named myObject I can find out its type in JSP EL like this:

${myObject['class']}

But if I have a java.util.Map stored as a request attribute myMap, and I put this in my page...

${myMap['class']}

...the Map is searched for an entry whose key is "class". This makes sense, otherwise we could never retrieve anything in EL from a Map with a key of "class".

So how do I display the type of my Map in an EL statement?

(And most of you will want to ask me: "Why do you care?". Well, today I was working on a train with no Internet connection and I had to iterate a java.util.HashMap in a page, and I completely forgot how to do that. So, not being able to Google or SO it, I decided to find out what the type was (I knew it wasn't an actual java.util.HashMap, Tomcat turns it into something else) so I could go rummaging around in the Tomcat jar files and see what methods it exposed and maybe figure it out myself. Well, I couldn't find out the type via EL. I resorted to embedded Java inside <% %> tags. But it has been bothering me all day that I coulnd't find out with EL alone. So, that's why I care. It's eating me up.)

John Fitzpatrick
  • 4,207
  • 7
  • 48
  • 71

1 Answers1

1

If you are using EL 2.2+ you can simply use:

${myMap.getClass()}

An other possiblity could be writing a custom EL function or tag. There you could check if the object is an instance of java.util.AbstractMap.

Community
  • 1
  • 1
Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102