How to pass multiple parameters with same name to JSTL

In JSP EL, param can be used to retrieve URL parameters. For example:

1
2
3
<c:forEach items="${param}" var="currentParam">
XXX
</c:forEach>

However, if multiple values with same name are passed, only the first value can be retrieved. I’m not sure if it’s a bug of JSTL or it has been designed to work this way. The easiest solution is to get all parameters in JSP scriptlet and pass it to JSTL.

1
2
3
4
<%
Map<String, String[]> allparams = request.getParameterMap();
pageContext.setAttribute("allparams", allparams);
%>

Then use it in JSTL:

1
2
3
4
5
6
7
<c:forEach items="${allparams}" var="currentParam">
<c:out value='${currentParam.key}' />:
<c:forEach items="${currentParam.value}" var="currentValue">
<c:out value='${currentValue}' /> /
</c:forEach>
<br/>
</c:forEach>
Share