在写之前先看看
以前用<logic:iterate>实现把数据库中的数据展现:
[MainForm.jsp文件]
public class MainForm extends
...
{
private List list;
private String bookname;
private String bookauther;
private String publish;
........
}
private List list;
private String bookname;
private String bookauther;
private String publish;
........
}
mainForm.setList(list);
......
[view.jsp文件]//展现数据库信息
.....
< logic:iterate id = " list " name = " mainForm " property = " list " >
< tr >
< td >< bean:write name = " list " property = " bookname " /></ td >
< td >< bean:write name = " list " property = " bookauther " /></ td >
< td >< bean:write name = " list " property = " publish " /></ td >
</ tr >
</ logic:iterate >
.....
< logic:iterate id = " list " name = " mainForm " property = " list " >
< tr >
< td >< bean:write name = " list " property = " bookname " /></ td >
< td >< bean:write name = " list " property = " bookauther " /></ td >
< td >< bean:write name = " list " property = " publish " /></ td >
</ tr >
</ logic:iterate >
.....
[MainForm.jsp文件]
public
class
MainForm
extends
...
{
private String bookname;
private String bookauther;
private String publish;
........
}
private String bookname;
private String bookauther;
private String publish;
........
}
......
ArrayList < MainForm > list = new ArrayList < MainForm > ();
while (rs.next()) ... {
MainForm dataView=new MainForm();//在这Form中不存在list属性
dataView.setBookname(rs.getString(1));
dataView.setBookauther(rs.getString(2));
dataView.setPublish(rs.getString(3));
list.add(dataView);
}
request.setAttribute( " list " ,list);
......
ArrayList < MainForm > list = new ArrayList < MainForm > ();
while (rs.next()) ... {
MainForm dataView=new MainForm();//在这Form中不存在list属性
dataView.setBookname(rs.getString(1));
dataView.setBookauther(rs.getString(2));
dataView.setPublish(rs.getString(3));
list.add(dataView);
}
request.setAttribute( " list " ,list);
......
.....
< logic:iterate id = " q1 " name = " list " type = " com.songbx.struts.form.MainForm " >
< tr >
< td >< bean:write name = " q1 " property = " bookname " /></ td >
< td >< bean:write name = " q1 " property = " bookauther " /></ td >
< td >< bean:write name = " q1 " property = " publish " /></ td >
</ tr >
</ logic:iterate >
.....
< logic:iterate id = " q1 " name = " list " type = " com.songbx.struts.form.MainForm " >
< tr >
< td >< bean:write name = " q1 " property = " bookname " /></ td >
< td >< bean:write name = " q1 " property = " bookauther " /></ td >
< td >< bean:write name = " q1 " property = " publish " /></ td >
</ tr >
</ logic:iterate >
.....
在此另注意一点:在用request传值时,在<forward>中一定不能是redirect="true",否则找不到list