开发者

What is the legal EL syntax for "${param.mode${cntr}}" [duplicate]

This question already has answers here: How to nest an EL expression in another EL expression (2 answers) Closed 6 years ago.

I'm writing this:

<c:forEach var="cntr" begin="1" end="10">
 <c:set var="mycase" value="${param.mode${cntr}}" />
 <c:if test="${mycase != null}">
   <c:param name="mode${cntr}" value="${mycase}"/>
  </c:if>
</c:forEach>

The result I want is for the redirect that sits outside of this to inherit the values of param.mode1, param.mode2, etc. as if I wrote:

  <c:if test="${param.mode1 != null}">
    <c:param name="mode1" value="${param.mode1}"/>
  </c:if>
  <c:if test="${param.mode2 != null}">
    <c:param name="mode2" value="${param.mode2}"/>
  </c:if>
  <c:if test="${param.mode3 != null}">
    <c:param name="mode3" value="${param.mode1}"/>
  </c:if>
  <c:开发者_JS百科if test="${param.mode4 != null}">
    <c:param name="mode4" value="${param.mode2}"/>
  </c:if>
  <c:if test="${param.mode5 != null}">
    <c:param name="mode5" value="${param.mode1}"/>
  </c:if>
  <c:if test="${param.mode6 != null}">
    <c:param name="mode6" value="${param.mode2}"/>
  </c:if>

All help appreciated.


You've to set another variable with mode${cntr} and to get the associated value using brace notation wherein you can pass a dynamic key.

<c:forEach var="cntr" begin="1" end="10">
    <c:set var="mode" value="mode${cntr}" />
    <c:set var="mycase" value="${param[mode]}" />
    <c:if test="${mycase != null}">
        <c:param name="mode${cntr}" value="${mycase}"/>
    </c:if>
</c:forEach>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜