JaveBean
package
ch9;


public
class
TestBean
...
{
private String name;
private String age;

public String getAge() ...{
return age;
}

public void setAge(String age) ...{
this.age = age;
}

public String getName() ...{
return name;
}

public void setName(String name) ...{
this.name = name;
}
}
package
ch9;

import
java.util.ArrayList;
import
java.util.HashMap;
import
java.util.HashSet;
import
java.util.List;
import
java.util.Map;
import
java.util.Set;

import
javax.servlet.http.HttpServletRequest;

import
com.opensymphony.webwork.interceptor.ServletRequestAware;
import
com.opensymphony.xwork.Action;
import
com.opensymphony.xwork.ActionSupport;


/** */
/**
* @author $author
*/

public
class
TestIteratorAction
extends
ActionSupport
implements
ServletRequestAware
...
{

HttpServletRequest request=null;
TestBean testBean1=new TestBean();
TestBean testBean2=new TestBean();
List a=new ArrayList();
Map b=new HashMap();
Set c=new HashSet();

public List getA() ...{
return a;
}

public void setA(List a) ...{
this.a = a;
}

public Map getB() ...{
return b;
}

public void setB(Map b) ...{
this.b = b;
}

public void setServletRequest(HttpServletRequest request) ...{
this.request=request;
}
public String execute() throws Exception

...{
testBean1.setAge("11");
testBean1.setName("gaoxiang");
testBean2.setAge("22");
testBean2.setName("yulihua");
a.add(testBean1);
a.add(testBean2);
b.put(5,testBean1);
b.put(3,testBean2);
b.put(11,testBean2);
b.put(9,testBean1);
c.add(testBean1);
c.add(testBean2);
request.setAttribute("a", a);
request.setAttribute("b", b);
request.setAttribute("c", c);
return Action.SUCCESS;
}

public Set getC() ...{
return c;
}

public void setC(Set c) ...{
this.c = c;
}
}
<%
...
@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"
%>
<!
DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"
>
<
html
>
<
head
>

<%
...
@ taglib uri="webwork" prefix="ww"
%>
<
meta
http-equiv
="Content-Type"
content
="text/html; charset=GB18030"
>
<
title
>
Insert title here
</
title
>
</
head
>
<
body
>
The object output:
<
br
>
<
ww:property
value
="#request['a']"
/><
br
>
<
ww:property
value
="#request['b']"
/><
br
>
<
ww:property
value
="#request['c']"
/><
br
>

<
br
>
The List output:
<
br
>
<
ww:iterator
value
="a"
>
<
ww:property
value
="name"
/>
+
<
ww:property
value
="age"
/><
br
>
</
ww:iterator
>

<
br
>
The Set output;
<
br
>
<
ww:iterator
value
="c.iterator"
>
<
ww:property
value
="name"
/>
+
<
ww:property
value
="age"
/><
br
>
</
ww:iterator
>

<
br
>
The Map output:
<
br
>
<
ww:iterator
value
="b"
>
<
ww:property
value
="key"
/>
-
<
ww:property
value
="value.name"
/>
+
<
ww:property
value
="value.age"
/><
br
>
</
ww:iterator
>
</
body
>
</
html
>
























Action:
分别构造List,Set,Map三个最常用的集合,需要注意的是webwork遍历Map标签是根据key从小到大排序输出的,所以,建议把key作为序号保存,使用整形,如果是字符串行,排序是不定的,我没有找到对String key的排序设置方法
代码比较简单,效果可直接参考jsp


















































































JSP:




































输出结果:
The object output:
[ch9.TestBean@a06816, ch9.TestBean@111985e]
{3=ch9.TestBean@111985e, 5=ch9.TestBean@a06816, 9=ch9.TestBean@a06816, 11=ch9.TestBean@111985e}
[ch9.TestBean@111985e, ch9.TestBean@a06816]
The List output:
gaoxiang+11
yulihua+22
The Set output;
yulihua+22
gaoxiang+11
The Map output:
3-yulihua+22
5-gaoxiang+11
9-gaoxiang+11
11-yulihua+22
看最后的Map输出,是以整形的key升序(ASC)排列的