File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Accessing constants using EL" Watch "Accessing constants using EL" New topic
Author

Accessing constants using EL

Andr� Korsnes Bruns�l
Greenhorn

Joined: Aug 22, 2005
Posts: 6
I have a class called Constants.java 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.

Thanks
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
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: http://www.javaranch.com/journal/200508/Journal200508.jsp#a1

And another post about it:
http://forum.java.sun.com/thread.jspa?threadID=508847
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60049
    
  65

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] [Bear's FrontMan] [About Bear] [Books by Bear]
Andr� Korsnes Bruns�l
Greenhorn

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: http://aspose.com/file-tools
 
subject: Accessing constants using EL
 
Similar Threads
static methods
Document or not? gazillion public constants in one class
Constants in Classic Tag
Which is better (Accessing constants defined in interface)
Which is better? Declaring constants in a class or Declaring them in interface?