jsp遍历struts的action的list?
有林 2015-08-26 11:51:51 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
</head>
<body>
<s:form action="ToBookList">
<table border="1" width="50%" align="center">
<tr bgcolor="#cccc00">
<td>编号</td><td>书名</td><td>价格</td><td>类型</td><td>作者</td><td>数量</td>
</tr>
jsp
<s:iterator value="list" id="book" status="st">
<tr align="center">
<td align="center"><s:property id="book" value="booknumber"/></td>
<td align="center"><s:property value="#book.bookname"/></td>
<td align="center"><s:property value="#book.bookprice"/></td>
<td align="center"><s:property value="#book.booktype"/></td>
<td align="center"><s:property value="#book.getBookauthor()"/></td>
<td align="center"><s:property value="#book.booksum"/></td>
</tr>
</s:iterator>
</table>
</s:form>
</body>
</html>
action:
package library.struts2.action;
import java.util.List;
import library.Bean.BookBean.Book;
import library.Spring.Interface.IBookService;
import com.opensymphony.xwork2.ActionSupport;
public class BookAction extends ActionSupport{
private IBookService bookservice;
private List<Book> list;
//list的setter和getter方法
public List<Book> getList() {
return list;
}
public void setList(List<Book> list) {
this.list = list;
}
//service的setter和getter方法
public IBookService getBookservice() {
return bookservice;
}
public void setBookservice(IBookService bookservice) {
this.bookservice = bookservice;
}
public String execute() throws Exception{
list = bookservice.getAllBook();
return SUCCESS;
}
}