0

我想用jsp迭代这组代码,(我用的是Netbeans 7.2.1)

<div class ="grid">
        <div class="img">
            <a target="_blank" href="Selected_Game.jsp?gameid=<%=rs.getString(1)%>">
                <img src="<%=rs.getString(2)%>" alt="">
            </a>
            <div class="desc">
                <div class="GName"> 
                    <%=rs.getString(3)%></div>
                <div class="Cost">Rs.<%=rs.getInt(5)%></div>
            </div>
        </div>
4

3 回答 3

1

我相信,您正在从数据库中检索数据。然后,像这样编写代码

<div class ="grid">
<% 
while (rs.next()) {  // check for next row and display data accordingly
%>
  <div class="img">
        <a target="_blank" href="Selected_Game.jsp?gameid=<%=rs.getString(1)%>">
            <img src="<%=rs.getString(2)%>" alt="">
        </a>
        <div class="desc">
            <div class="GName"> 
                <%=rs.getString(3)%></div>
            <div class="Cost">Rs.<%=rs.getInt(5)%></div>
        </div>
    </div>

<% 
 }   //end of while loop
%>
</div>
于 2012-12-19T16:33:32.950 回答
0

不确定您是否想将该代码放入循环中,或者像包含一样重用它。

迭代(循环)

您可以将该代码包装在 for 循环中:

<% for (int i=0; i<limit; i++) { %>
  html and jsp code in here
  <%= i %>
<% } %>

迭代(重复)

您可以将该代码放在片段/标签中并包含它:

<jsp:include page="hello.jsp"/>
于 2012-12-19T16:30:26.773 回答
0

使用 JSTL 的C:for-each 标签

 <c:forEach var="person" items="${people.people}" varStatus="rowCounter">

      </c:forEach>
于 2012-12-19T16:30:59.410 回答