Struts2标签遍历List>

时间:2022-05-09 10:37:22
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {

private List<Map<String, String>> list;

@Override
public String execute() {
list = new ArrayList<Map<String, String>>();

Map<String, String> map = new HashMap<String, String>();
map.put("name", "zhangsan");
map.put("sex", "boy");
map.put("age", "25");

list.add(map);

return "success";
}

public List<Map<String, String>> getList() {
return list;
}

public void setList(List<Map<String, String>> list) {
this.list = list;
}

}

jsp中使用s:iteraotr标签遍历List

<s:iterator id="map" value="list" status="state"><!-- 打印List --><s:property value="list[#state.index]" /> <br><!-- 打印Map --><s:iterator value="list[#state.index]"><s:property value="key" />: <s:property value="value" /><br></s:iterator></s:iterator>

输出如图:

Struts2标签遍历List<Map<String, String>>