How to get a value of an object's property when the property name is a variable itself in JSP? [duplicate]

99封情书 提交于 2020-01-04 13:27:53

问题


HI,

Here's my dilemma. The below code is obviously wrong but it give you the idea on what I need to accomplish.

<c:forEach var="object1" items="${model.listofObjects1}">
  <tr>
    <c:forEach var="object2" items="${model.listofObjects2}">
      <td>${object1.${object2}}</td>
    </c:forEach>
  </tr>
</c:forEach>

Any ideas on how to make this look up?


回答1:


Use the brace notation.

<td>${object1[object2]}</td>


来源:https://stackoverflow.com/questions/4957685/how-to-get-a-value-of-an-objects-property-when-the-property-name-is-a-variable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!