File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Accessing constants using EL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Accessing constants using EL" Watch "Accessing constants using EL" New topic

Accessing constants using EL

Andr� Korsnes Bruns�l

Joined: Aug 22, 2005
Posts: 6
I have a class called that contains a number of static final constants.

When I try accessing them by ${Constants.CONST_NAME}, nothing is returned. I have also tried creating a getCONST_NAME() method in the class but this does not return anything either.

If I use <%= Constants.CONST_NAME %> the correct value is returned.

Is the root of my problem that I have missed something, or can it be some kind of setting on my Tomcat server I have not set?

I'm using Tomcat 5.0.27.

Stefan Evans

Joined: Jul 06, 2005
Posts: 1518
Nope you haven't missed anything.

The getCONST_NAME() method should work though, as long as it is not static. ie public String getCONST_NAME();

Another way to do it is via a map.
Bear recently contributed an article on this:

And another post about it:
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63529

The EL has no means to access class constants.

There was an extended conversation on this subject a while back in the very forum. If you look back (perhaps a month or os) you may find it.

It is also a subject that is mentioned in this JavaRanch Journal article.

[Bear and Stefan go BUMP!]
[ August 29, 2005: Message edited by: Bear Bibeault ]

[Asking smart questions] [About Bear] [Books by Bear]
Andr� Korsnes Bruns�l

Joined: Aug 22, 2005
Posts: 6
Thank you for your quick responses Stefan and Bear.

The section on Constants in Bear's article worked like a charm.

Thanks again!
I agree. Here's the link:
subject: Accessing constants using EL
It's not a secret anymore!