Originally posted by Kinjal Sonpal:
I need to access certain constants (those typical public static final ones), which are global across the application, including other layers. How do I use these in jsp pages and where do I declare them?
I have thought of putting the Interface (having constants) in application scope, by a servlet. But I'm not sure whether this is the correct approach, or there are better/smoother approaches. Is it possible to configure this in web.xml?
There are probably several ways to do this, but one solution is to define a class (not an interface) with all your static finals that you will use as a bean with application scope. You can instantiate it in the servlet and add it to the servlet context with
getServletContext().setAttribute("objName", obj)
or you can put a useBean tag in the JSP with application scope:
<jsp:useBean id="beanName" class="MyPackage.MyConstantsClass" scope="application" />
Then you can refer to the constants in your JSP code as an expression
<%= constantsBean.MY_CONSTANT_1 %>
or with the expression language of JSP 2.0
${constantsBean.MY_CONSTANT_1}
Sorry about the empty post above.