码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-01-08 21:37:40      阅读:317      评论:0      收藏:0      [点我收藏+]

标签:

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>>

标签:

原文地址:http://blog.csdn.net/itmyhome1990/article/details/42489007

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!