3

In my project, I set up the Constant class like this

class Constant {
    public static final String PARA = "para";

    public Integer getPARA () {
        return PARA;
    }
}

in order to access the constant from the jsp through el

<!-- test.jsp -->
<jsp:useBean id="cons" class="com.test.Constant" scope="session"/>

...
${cons.PARA}

Now, in my java code, I set an attribute for that constant

// foo.java
request.setAttribute(Constant.PARA, "this is a param");

To access that attribute in the jsp, we could do ${para} but how can I access the attribute value ("this is a param") through that constant variable cons.PARAM ? In short, how can we convert the following code into jstl ?

<%=request.getAttribute(Constant.PARA)%>
Thai Tran
  • 9,815
  • 7
  • 43
  • 64

1 Answers1

3

Just found out 1 way to do it

<c:set var='param' value="${cons.PARA}" />

<c:out value="${requestScope[param] }" />
Thai Tran
  • 9,815
  • 7
  • 43
  • 64