0

In .jsp pages by using Expression Language, i am wanting to retrieve all header names along with their values.

<%@ 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>

header is as far as i know a map

  • The quotation marks are required for specifying a property in a JavaBean or a key in a map

But <td>${header["${item}"]}</td> return null, even though <td>${item}</td> return the header name.

1 Answers1

2
<td>${header["${item}"]}</td>

should be

<td>${header[item]}</td>

Alternatively you could use the implicit header object in jstl

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

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

</c:forEach>
ramp
  • 1,256
  • 8
  • 14