Scriptlet is pedestrian. Make sure that you are using jsp 2.x and add a taglib with a function like the one below. It will get any object type, not just strings, and could be modified to include dot notation for any constants class. You can make a custom functions TLD once and reuse it for every project you ever do in the future. As a final note, if this constants class is for actual user viewable content, not keys and the like, use a localizable resource file and jstls fmt:message instead. /** * usage: ${yourprefix:constant('constantName')} */ public static Object getConstant(String constantName) { try { Field field = Constants.class.getDeclaredField(constantName); return field.get(null); } catch (Exception e) { return null; } } in your tld: <function> <name>constant</name> <function-class>gov.fema.web.nimcast.tools.taglib.Functions</function-class> <function-signature>Object getConstant(java.lang.String)</function-signature> </function> |
|