[英]JSP EL: Why does the not operator evaluates to true on undeclared variable
[英]Getting variable in JSP EL by constant does not work
我使用GlassFish 4.1 web profile,据我所知使用EL 3.0。 我按照此处的说明完成了所有操作 - https://stackoverflow.com/a/3735006/5057736但是我对此解决方案的实现不起作用。
这是我不变的课程
public class CommonKeys {
public static final String TITLE = "SOME_KEY";
}
这是我设置属性的方式:
request.setAttribute(CommonKeys.TITLE, "TEST");
这是我的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>
这是我得到的输出
Method 1:TEST
Method 2:
Method 3:TEST
为什么方法2不起作用?
<c:set var="TITLE" value="<%=CommmonKeys.TITLE%>" />
Method 2:${requestScope[TITLE]}
按上述方式更改代码,应该可以正常工作。 这个对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.