mohsen.nour
mohsen.nour

Reputation: 1147

Print invidivual names and values of ${headerValues} using EL in JSP

I am trying to print the implicit EL object ${headerValues} in a JSP page as below:

<!DOCTYPE html>
<html>
  <head>
    <title>Insert title here</title>
  </head>
  <body>
    ${headerValues}
  </body>
</html>

However, it prints the following output:

javax.servlet.jsp.el.ImplicitObjectELResolver$ImplicitObjects$8@19255988

How can I print the individual header names and values?

Upvotes: 0

Views: 783

Answers (1)

BalusC
BalusC

Reputation: 1108722

It's a Map<String, String[]>. So, you need to iterate over it in order to access the entries. You can use JSTL <c:forEach> for this. Every iteration will give you a Map.Entry which in turn has getKey() and getValue() methods. The getKey() will return the header name. The getValue() will return the header values as a String[]. You'd need another <c:forEach> to iterate over it.

In a nutshell:

<dl>
    <c:forEach items="${headerValues}" var="entry">
        <dt>${entry.key}</dt>
        <c:forEach items="${entry.value}" var="headerValue">
            <dd>${headerValue}</dd>
        </c:forEach>
    </c:forEach>
</dl>

Upvotes: 3

Related Questions