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