我有一张表
create table book(
        id integer(5) primary key,
name varchar(15),
author varchar(10),
price integer(3),
publisher varchar(15)
);
在struts Action中得到全部的书:
         List<Book> book = dao.getAllBook();
        request.setAttribute("books", book);
在jsp页面中得到:
<table>
<c:forEach items="${requestScope.books}" var="book">
<tr>
<td>${book.name }</td>
</tr>
</c:forEach>
</table>
得到的应该是:
       书1
       书2
       书3
       书4
       书5
       书6
       书7
       书8
       .....
现在我想得到:
        书1   书2    书3
       书4   书5    书6
       书7   书8该怎么做啊???

解决方案 »

  1.   

    用<%for(...){..}%>吧
    简单
      

  2.   

                   <table width='100%'  height="226" border='0' cellspacing='0' cellpadding='5'>
                        <%if(imgList==null||imgList.size()<1){%>
                    <tr><td align='center'>没有任何文件</td></tr>
                        <%}else{%>
                    <tr align='center'>
                        <%
                        intRowCount=imgList.size();
                
                        //记算总页数 
                        intPageCount = (intRowCount+intPageSize-1) / intPageSize; 
        
                         //调整待显示的页码 
                        if(intPage >intPageCount) intPage = intPageCount;
                        
                              //显示记录数 
          int i=0;
          if(intPage<2){
           i=0;
          }else{
           i=intPageSize*(intPage-1);
          }
         while(i<intPageSize*intPage&&i<intRowCount){
      
             imgModel =(ImgBookModel) imgList.get(i);
     
                        %>
                        <td width='33%'><table align=center border=1  style='BORDER-COLLAPSE: collapse'  cellpadding=0 cellspacing=0  bordercolor='#CCCCCC'><tbody><td><a href="/pages/viewImg.jsp?id=<%=imgModel.getId()%>"><img alt=""  onmousewheel="return   bbimg(this)"  src='/smallpic/<%=imgModel.getPicUrl()%>' border='0' width='120' height='120'></a></td></tbody></table><br>
                        <%if(imgModel.getTitle().length()<=5){%>
                        <%=imgModel.getTitle()%>
                        <%}else{%>
                        <%=imgModel.getTitle().substring(0,5)%><%}%>"</a> | 浏览:"<%=imgModel.getClick()%>"</td>
                              <%i++;
                              if(i%3==0){
                              %>
                              <tr>
                              <%}}}%>  
                    </tr> 
                    </table>  
      

  3.   


      //翻页信息
      int intPageSize=0; //一页显示的记录数 
      int intRowCount=0; //记录总数 
      int intPageCount=0; //总页数 
      int intPage; //待显示页码 
      String strPage;
       
      //设置一页显示的记录数 
      intPageSize = 9; 
         
      //取得待显示页码 
      strPage = request.getParameter("page");   if(strPage==null||"".equalsIgnoreCase(strPage)){//表明没有page这一个参数,此时显示第一页数据 
      intPage = 1; 
      }else{//将字符串转换成整型 
      intPage = java.lang.Integer.parseInt(strPage); 
      if(intPage< 1){ 
      intPage = 1; 
      } 
      } 
      

  4.   

    可以这样:
    <table> 
    <c:forEach items="${requestScope.books}" var="book" varStatus="status"> 
    <c:if test="{status%3==0}">
    <tr> 
    </c:if>
    <td>${book.name } </td> 
    <c:if test="{status%3==0}">
    </tr> 
    </c:if>
    </c:forEach> 
    </table> 
      

  5.   


    <table> 
    <c:forEach items="${requestScope.books}" var="book" varStatus="status"> 
    <c:if test="{status%3==0||status==1}">
    <tr> 
    </c:if>
    <td>${book.name } </td> 
    <c:if test="{status%3==0||status==1}">
    </tr> 
    </c:if>
    </c:forEach> 
    </table> 
      

  6.   

    贴两边都没贴对这回对了
    <table> 
    <c:forEach items="${requestScope.books}" var="book" varStatus="status"> 
    <c:if test="${status%3==0||status==1}">
    <tr> 
    </c:if>
    <td>${book.name } </td> 
    <c:if test="${status%3==0||status==1}">
    </tr> 
    </c:if>
    </c:forEach> 
    </table> 
      

  7.   


    <table> 
       <%
          for(int i=0; i<booksList.size(); i++){
             Book book = (Book) booksList.get(i);
             if(i%3==1){  // 每行三个
                 out.print("<tr>");
             }
             out.print("<td>");
             out.print(book.getName());
             out.print("</td>"); 
          }
       %>
    </table> 
      

  8.   

    <table> 
    <c:forEach items="${requestScope.books}" var="book"> 
    <tr> 
    <td>${book.name } </td> 
    <c:set var="i" value="${i+1}"/>
    <c:if test="${i%3==0}">
    </tr><tr>
    </c:if>
    </tr> 
    </c:forEach> 
    </table>
      

  9.   

    <table>  
    <c:if test="${not empty requestScope.books}">
    <tr>  <c:forEach items="${requestScope.books}" var="book" varStatus="index">  
    <td>${book.name }  </td>  
    <c:set var="i" value="${index.count}"/>
    <c:if test="${index.count %3==0}"> 
    </tr> <tr>
    </c:if> 
    </c:forEach>  
    <%for(int j=0;j<(3-i%3);j++){%>
    <td>&nbsp;</td>
    <%}%>
    </tr>  
    </c:if>
    </table>
      

  10.   

    貌似应该这样. 是 循环 <td></td>. 而且不能忘记 总记录数 非 3 的整倍数的时候, 最后一行还要 补 &nbsp; 的. 
    <table>   
    <c:if test="${not empty requestScope.books}"> 
    <tr>   <c:forEach items="${requestScope.books}" var="book" varStatus="index">   
    <td>${book.name }   </td>   
    <c:set var="i" value="${index.count}"/> 
    <c:if test="${index.count %3==0}">  
    </tr><tr> 
    </c:if>  
    </c:forEach>   
    <%
      if(i%3 != 0){
      for(int j=0;j <(3-i%3);j++){%> 
      <td>&nbsp; </td> 
    <%}}%> 
    </tr>   
    </c:if> 
    </table>
      

  11.   

    这个调用status好像错了,我记得是status.count调用状态值,貌似这个值就跟FOR循环里的自己定义的I一样,而且好像从0开始的
      

  12.   

    <logic:present 
    <logic:iterate 再来个<logic:empty  到3个一换行就行拉
      

  13.   

    <div>
    <c:set value="0" var="i"></c:set>
    <c:forEach items="${requestScope.books}" var="book">
    <c:if test="${i%3==0}"><br></c:if>
    <div>
    ${book.name }
    </div>
    <c:set value="${i+1}" var="i"></c:set>
    </div>