How to reference constants in EL?

How do you reference an constants with EL on a JSP page?

I have an interface Addresses with a constant named URL. I know I can reference it with a scriplet by going: , but how do I do this using EL?

This is not possible using standard EL in its current 2.2 release. There are however several ways to achieve the requirement:

 

Put them in a Map which you put in the application scope. In EL, map values are accessible the usual Javabean way by ${map.key} or ${map['key.with.dots']}.

 

Use  of the Unstandard taglib (maven2 repo here):

 





This way they are accessible the usual Javabean way by ${constants}.

 

Use Javaranch's CCC  as desribed somewhere at the bottom of this article.

 

 

 

This way they are accessible the usual Javabean way by ${constants} as well.

 

If you're using JSF2, then you could use  of OmniFaces.

 

 

 

This way they are accessible the usual Javabean way by #{YourConstants} as well.

 

Create a wrapper class which returns them through Javabean-style getter methods.

 

Create a custom EL resolver which first scans the presence of a constant and if absent, then delegate to the default resolver, otherwise returns the constant value instead.