views:

347

answers:

1

Is it possible in JSP to get the type of Object in List, just like we do in Java

myDataBind.getResultsList().get(0).getClass();

or is it possible to achieve something like this:

if ( myDataBind.getResultsList().get(0) instanceOf MyClass ) {
  doThis;
}

i don't prefer scriptlets, but if it is not possible to do without scriptlets then Please let me know even that solution too.

  • assuming all objects in list are of same type.
+1  A: 

Using JSTL, you can retrieve everything that uses the JavaBean spec - if you want to use getClass() in java, you would use .class in JSTL:

This would write out your classname:

${myList[0].class}
Ben
Neat. ${myList[0].class.name} would be the classname though (a simple toString will print "class java.lang.String" or "interface java.util.Map")
Thilo