在 jsp(Spring MVC) 中访问 java 代码片段之外的变量



在我的场景中,我有如下代码:

     <c:forEach items="${dbEntries}" var="c" varStatus="loop">
                    <tr> 
                          <% 
                              int i = 0;
                              System.out.println(i);
                          %>
                          <td rowspan="1">${c.getRh_name()}</td>                                 
                          <td rowspan="1">${c.getIpm_name()}</td>` 
                    </tr>
      </c:forEach>

现在我想从 HTML 访问变量。

<h1>${i}</h1>

但它没有显示。谁能帮忙??

像这样在 jsp 中使用 jstl 而不是 java 代码。

    <c:set var="salary" scope="session" value="${2000*2}" /> 
     <c:out value="${salary}" /> 
    <c:forEach begin="1" end="5" step="1">
         <c:set var="salary" value="${2000*2}" /> 
    </c:forEach> <c:out value="${salary}" />

最新更新