Jstl for each loop items attribute use another variable not working

允我心安 提交于 2020-01-07 09:15:10

问题


getResults is list

case 1 :

 <c:forEach items="${getResults} var="s1">
      ${s1}
 </c:forEach>

case 2 :

 <c:set var="res" value="getResults" />
 <c:forEach items="${res} var="s2">
      ${s2}
 </c:forEach>

In above code case (1) is printing list of results fine

but in case (2) just res is printing

Iam trying to print results using case 2 please help me out

that is need for my project


回答1:


<c:set var="res" value="getResults" />

This sets the res variable to the string "getResults". If you want it to be a reference to the same object as the getResults attribute, you want

<c:set var="res" value="${getResults}" />

This is completely unnecessary though, since you can iterate directly on ${getResults}



来源:https://stackoverflow.com/questions/24998497/jstl-for-each-loop-items-attribute-use-another-variable-not-working

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