使用<logic:iterate/>标签:1.在Action中将数据组织到一个Collection, Enumerator,Iterator, Map或者Array类型的对象,根据你程序的需要将这个对象存入request或session甚至application中。例如:
必须现有一个Bean
public class infoBean {
private String name;
private String id;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
然后在Action中存入Array
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
//.......
java.util.List list = new java.util.ArrayList();
for(int i=0;i<10;i++){
infoBean a = new infoBean();
a.setId(...);
a.setName(...);
list.add(a);
}
httpServletRequest.setAttribute("list",list);
...
}2. 在Action所Forward的Jsp页面:
<table>
<logic:iterate id="aRow" name="list">
<tr>
<td><bean:write name="aRow" property="id"/></td>
<td><bean:write name="aRow" property="name"/></td>
</tr>
</logic:iterate>
</table>
必须现有一个Bean
public class infoBean {
private String name;
private String id;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
然后在Action中存入Array
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
//.......
java.util.List list = new java.util.ArrayList();
for(int i=0;i<10;i++){
infoBean a = new infoBean();
a.setId(...);
a.setName(...);
list.add(a);
}
httpServletRequest.setAttribute("list",list);
...
}2. 在Action所Forward的Jsp页面:
<table>
<logic:iterate id="aRow" name="list">
<tr>
<td><bean:write name="aRow" property="id"/></td>
<td><bean:write name="aRow" property="name"/></td>
</tr>
</logic:iterate>
</table>
信箱:[email protected]
我如果不用一般的bean而是用formbean,而且frombean有2个数组或者ArrayList(name1,name2)的属性,我在jsp里面画table时应该怎么做呢?
table样式:
name1 name2
value11 value21
value12 value22
...谢谢了。
http://community.csdn.net/Expert/topic/3375/3375336.xml?temp=.3042566
谢谢了。