Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsp 表达式语言-标头值为空_Jsp_Foreach_El - Fatal编程技术网

Jsp 表达式语言-标头值为空

Jsp 表达式语言-标头值为空,jsp,foreach,el,Jsp,Foreach,El,在使用表达式语言的.jsp页面中,我希望检索所有标题名及其值 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <table> <tr> <th>Name</th> <th>Value</th> </tr> <c:forEach items="${pageCon

在使用表达式语言的.jsp页面中,我希望检索所有标题名及其值

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<table>
    <tr>
        <th>Name</th>
        <th>Value</th>
    </tr>
    <c:forEach items="${pageContext.request.headerNames}" var="item">
    <tr>
        <td>${item}</td>
        <td>${header["${item}"]}</td>
    </tr>
    </c:forEach>
</table>

名称
价值
${item}
${header[“${item}”]}
据我所知,这是一张地图

  • 引号用于指定JavaBean中的属性或映射中的键
但是
${header[“${item}]}
返回null,即使
${item}
返回头名称。

${header[“${item}]}
<td>${header["${item}"]}</td>
应该是

<td>${header[item]}</td>
${header[item]}
或者,您可以在jstl中使用隐式头对象

<c:forEach items = "header" var = "h">

Header Name ${h.key}
Header Value ${h.value}

</c:forEach>

标头名称${h.key}
标题值${h.Value}
${header[“${item}”]}
应该是

<td>${header[item]}</td>
${header[item]}
或者,您可以在jstl中使用隐式头对象

<c:forEach items = "header" var = "h">

Header Name ${h.key}
Header Value ${h.value}

</c:forEach>

标头名称${h.key}
标题值${h.Value}

在我的示例中没有引号=无法解析表达式[${header[${item}]}],但它像一个符咒一样在header对象上迭代并获取键和值。请仔细查看:),该项周围没有“$”或“{”符号。它只是简单的[item]我现在明白了,我已经看这个太久了xD我试过了,但是我得到了一个javax.servlet.jsp.el.ImplicitObjectELResolver$ScopeMap$ScopeEntry不能转换为java.lang.String---${header[item]}哦,哇,这是一个Map.Entry。也许你应该尝试item.key来代替item。很抱歉,我没有一个工作环境来尝试它,因为它可以工作:)在我的示例中没有引号=无法解析表达式[${header[${item}]}]但是它像一个符咒一样在header对象上迭代并获得键和值。请仔细查看:),该项周围没有“$”或“{”符号。它只是普通的[item]我现在明白了,我已经看这个太久了xD我试过了,但是我得到了一个javax.servlet.jsp.el.ImplicitObjectELResolver$ScopeMap$ScopeEntry不能转换为java.lang.String---${header[item]}哦,哇,这是一个Map.Entry。也许你应该试试item.key来代替item。对不起,我没有一个工作环境来试用它。它可以工作:)这不是它的副本。这不是它的副本。