Accessing a variable outside java code fragment in a jsp(Spring MVC)

耗尽温柔 提交于 2020-01-07 09:02:23

问题


in my scenario i have a code like below:

     <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>

now i want to access the variable from html. like below

<h1>${i}</h1>

but its not displaying.can anyone help??


回答1:


Use jstl instead of java code inside jsp like this.

    <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}" />


来源:https://stackoverflow.com/questions/49423872/accessing-a-variable-outside-java-code-fragment-in-a-jspspring-mvc

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