我有一个jsp文件,其中包含以下代码:
<%
while(rs.next()){ //rs is the resultser
%>
<tr bgcolor="#FFFFFF" onMouseOver="this.bgColor='gold';" onMouseOut="this.bgColor='#FFFFFF';">
<td width="3%"><span style="font-size: 8pt"><%=i=i+1%></span></td>
<td width="10%"><span style="font-size: 8pt">
<a href="cir_view.jsp?cir_id=<%=rs.getString("cir_id")%>
我想将 while 循环更改为 for 循环。我尝试了这个,但是,我在尝试检索 cir_id 的值时遇到了困难。这是我的代码:
<%
for(int j=1; j<=totalCols; j++) {
%>
<tr bgcolor="#FFFFFF" onMouseOver="this.bgColor='gold';" onMouseOut="this.bgColor='#FFFFFF';">
<td width="3%"><span style="font-size: 8pt"><%=j=j+1%></span></td>
<td width="10%"><span style="font-size: 8pt">
<a href="cir_view.jsp?cir_id=<%=rs.getString("cir_id")%>" >>> Here is the change??
可以帮忙修改一下吗?
最佳答案
代码如下:
<%
for(int j=1; j<=totalCols && rs.next(); j++) {
%>
.....
<a href="cir_view.jsp?cir_id=<%=rs.getString("cir_id")%>"
您可以将 rs.next() 保留在 for 循环本身中
关于java - 如何将 while 循环改为 for 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3402854/