Constants created in Java Interfaces & Classes can be used in JSP pages by including the unstandard taglib provided by Apache. Rather than accessing your constants using scriptlet, this taglib helps you define your Java Constants in JSP pages using the useConstants tag. The useConstants tag exposes all of the public constants in a class/interface as a map stored in a scoped attribute. The scope may be specified, but defaults to page scope. So once declared the constant variable can be used in any EL expression.
To use the tags
from this library in your JSP pages, add the following directive at
the top of each page:
<%@ taglib uri="http://jakarta.apache.org/taglibs/unstandard-1.0" prefix="un" %>
where "un"
is the tag name prefix you wish to use for tags from this library
To expose all of
the constants in the Integer class
<un:useConstants var="const" className="java.lang.Integer" />
Attributes: var
(required), className (required), scope (optional, default - page)
var - Name of the
scoped attribute into which the map will be stored.
className - Fully
qualified name of the class from which constants will be extracted.
scope - Scope into
which to store the map. Default is page scope.