1

I use GlassFish 4.1 web profile which as I understand uses EL 3.0. I did everything as was explained here - https://stackoverflow.com/a/3735006/5057736 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?

Pavel_K
  • 10,748
  • 13
  • 73
  • 186
  • @Jozef Chocholacek I did as was explained at the link you provided. However, it doesn't work. That is the reason of this question. – Pavel_K Jun 13 '17 at 13:00
  • Looks like a bug/omission in the EL specification/implementation (no time to investigate where) that you cannot use constant as a key. I'd try `` and then `${requestScope[_key]}`, but that would be just a workaround. – Jozef Chocholacek Jun 13 '17 at 13:07
  • @Jozef Chocholacek Thank you for your suggestions. I also think that `something` doesn't work. But what is this `something` I can't find - that is why I asked this question. Could you remove this `possible duplicate`? – Pavel_K Jun 13 '17 at 13:11

1 Answers1

0
<c:set var="TITLE" value="<%=CommmonKeys.TITLE%>" />
Method 2:${requestScope[TITLE]}

Change your code as per above, should be working fine. It works for me.

Arvind Chavhan
  • 488
  • 1
  • 6
  • 14