Search code examples
jspjstlel

Concatenating in EL param


Using JSP/JSTL, I am iterating over a list of items:

<c:forEach var="item" items="${list}" varStatus="loop"> </c:forEach>

Within the loop, I would like to retrieve a parameter based on the loop index. I know that to access a parameter (e.g. named "p"), I would do: ${param.p} and to access the loop index, I would do: ${loop.index}

However, how would I combine these to retrieve a parameter (e.g. named "p0", where 0 is the loop index)? I tried the following, but it did not work.

1) ${param['p'+=loop.index]}
2) <c:set var="p" value="p${loop.index}"/> ${param.p}


Solution

  • I was able to resolve this by first creating a new variable and then using bracket notation to retrieve the parameter:

    <c:set var="p" value="p${loop.index}"/> ${param[p]}