I use GlassFish 4.1 web profile which as I understand uses EL 3.0. I did everything as was explained here - https://mcmap.net/q/194973/-how-to-reference-constants-in-el however my implementation of this solution doesn't work.
This is my constant class
public class CommonKeys {
public static final String TITLE = "SOME_KEY";
}
This is how I set attribute:
request.setAttribute(CommonKeys.TITLE, "TEST");
This is my jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page import="org.temp.CommonKeys"%>
<div> Method 1:<%=request.getAttribute(CommonKeys.TITLE)%></div>
<div> Method 2:${requestScope[CommmonKeys.TITLE]}</div>
<div> Method 3:${requestScope["SOME_KEY"]}</div>
This is the output I get
Method 1:TEST
Method 2:
Method 3:TEST
Why does Method 2 not work?
<c:set var="_key" value="${CommmonKeys.TITLE}" />
and then${requestScope[_key]}
, but that would be just a workaround. – Ephesussomething
doesn't work. But what is thissomething
I can't find - that is why I asked this question. Could you remove thispossible duplicate
? – Layfield