最近在做一个类似商城的东西
将数据库中的数据集取到List中。在jsp页面中用for each来输出
只能做到一行一个的输出
如#
  #
  #
  #
  #
我想做到可以设定一行输出几个,超出就换行的效果

一行5个
  #  #  #  #  #
  #  #  #  #  #
  #  #  #  #  #
  #  #  #的效果,不知道怎么实现
请大家帮忙

解决方案 »

  1.   

    每次5个数据保存到一个对象,再放入到list中,而不是一个个的放。
      

  2.   

    <c:forEach items="${list}" var="obj" varStatus="i">
       数据:${obj} <c:if test="${((i.index + 1)%5) eq 0}"><br></c:if>
    </c:forEach>
      

  3.   

    回复楼上的,你这个我是了一下,好像不行,我在把问题细化一下
    我的Product类
    {
    photopath
    product_name
    product_price
    }
    在struts 的action中从所有数据库中取得所有数据到productList中
    然后request.setAttribute("product.list", productlist);
    在jsp中<c:forEach items="${requestScope['product.list']}" var="products" varStatus="i"> 
    <table width="64" border="0">
    <table width="200" border="1">
    <tr>
    <td>
    <div> <a
    <img src="product/${products.photopath}"> </a>
    </div>
    </td>
    </tr>
    <tr>
    <td>
    <div>
    <h5>
    ${products.product_name}
    </h1>
    </div>
    </td>
    </tr>
    <tr>
    <td>
    <div>
    <h5>
    ${products.product_price}金币
    </h5>
    </div>
    </td>
    </tr>
    </table>
    <c:if test="${((i.index + 1)%5) eq 0}"> <br> </c:if> 

    </c:forEach>