how to get the element of a list inside jsp using JSTL?

前端 未结 3 1031
悲哀的现实
悲哀的现实 2020-12-15 07:24

I have such this code inside my Spring MVC java controller class:

@RequestMapping(value = \"jobs\", method = { RequestMethod.GET })
public String jobList(@Pa         


        
相关标签:
3条回答
  • 2020-12-15 08:05

    get is not a jstl function.

    <td>${stats[i.index].No}</td>
    
    0 讨论(0)
  • 2020-12-15 08:17

    In my opinion, the right answer is a combination of both of the answers you got:

    use varStatus attribute of c:foreach tag

    but:

    "get" is not a jstl function.

    <c:forEach var="jobs" items="${jobs}" varStatus="i">
       <c:set var="jobID" value="${jobs.jobId}"/>
      <table>
        <tr class="tr1">
            <td>${jobs.topic}</td>
            <td>${stats[i.index].no}</td>
        </tr>
      </table>
    </c:forEach>
    

    EDIT: this is the code finally used by the author of the question:

    <c:set var="stats" value="${jobStats}" />
    <c:forEach items="${jobs}" varStatus="i">
       <c:set var="jobID" value="${jobs[i.index].jobId}"/>
      <table>
        <tr class="tr1">
            <td>${jobs[i.index].topic}</td>
            <td>${stats[i.index].no}</td>
            <td>${jobID}</td>
        </tr>
      </table>
    </c:forEach>
    
    0 讨论(0)
  • use varStatus attribute of c:foreach tag

    <c:forEach var="jobs" items="${jobs}" varStatus="i">
       <c:set var="jobID" value="${jobs.JobId}"/>
      <table>
        <tr class="tr1">
            <td>${jobs.Topic}</td>
            <td>${stats.get(i.index).No}</td>
        </tr>
      </table>
    </c:forEach>
    
    0 讨论(0)
提交回复
热议问题