使用struts中的<logic:iterate>標記
下面用了一個小例子說明這一點
IterateBean
package beantest;
import org
public class IterateBean extends ActionForm {
private String[] name_coll = null;
public void setName_coll(String[] name_coll) {
this
}
public String[] getName_coll() {
return this
}
private String[] name_new = null;
public void setName_new(String[] name_new) {
System
this
}
public String[] getName_new() {
return this
}
}
IterateAction
package beantest;
import javax
import javax
import org
import org
import org
import org
public class IterateAction extends Action {
public ActionForward execute(
ActionMapping mapping
ActionForm form
HttpServletRequest request
HttpServletResponse response) throws Exception {
IterateBean ibean = (IterateBean) form;
String[] temp = {
ibean
temp = new String[] {
ibean
return mapping
}
}
iterate
<%@ page contentType=
<%@ taglib uri=
<%@ taglib uri=
<logic:iterate id=
<logic:iterate id=
name: <font color=red><%=iterate%></font> ; code: <font color=red><%=iterate_new%></font><br>
</logic:iterate>
★〓〓〓〓〓〓〓〓★<br>
<bean:include id=
<bean:write name=
</logic:iterate>
lower
<font color=blue>hello
struts
<?xml version=
<!DOCTYPE struts
<struts
<form
<form
</form
<action
<action path=
<forward path=
</action>
</action
</struts
web
<?xml version=
<!DOCTYPE web
<web
<servlet>
<servlet
<servlet
<init
<param
<param
</init
<load
</servlet>
<servlet
<servlet
<url
</servlet
</web
輸出效果
name: bitan ; code: aaaaa
name: bitan ; code: bbbbb
★〓〓〓〓〓〓〓〓★
hello
name: helen ; code: aaaaa
name: helen ; code: bbbbb
★〓〓〓〓〓〓〓〓★
hello
如上所示
要實現在一個循環中將多個變量同時輸出
From:http://tw.wingwit.com/Article/program/Java/ky/201311/28010.html