Getting variable in JSP EL by constant does not work

限于喜欢 提交于 2019-12-11 09:08:46

问题


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?


回答1:


<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.



来源:https://stackoverflow.com/questions/44518143/getting-variable-in-jsp-el-by-constant-does-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!