我有一张表
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该怎么做啊???
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该怎么做啊???
简单
<%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>
//翻页信息
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;
}
}
<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>
<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>
<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>
<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>
<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>
<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> </td>
<%}%>
</tr>
</c:if>
</table>
<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> </td>
<%}}%>
</tr>
</c:if>
</table>
<logic:iterate 再来个<logic:empty 到3个一换行就行拉
<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>