struts2_day02_15-封装数据到list集合_16-封装数据到map集合

封装到集合里面

封装数据到List集合

第一步action声明List

第二步生成list变量的setget方法

package com.hlg.data;

import java.util.List;

import com.hlg.entity.Book;
import com.hlg.entity.User;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
/**
 * 封装数据到list
 * @author Administrator
 *
 */
public class ListAction extends ActionSupport{

	private List<User> list;
	public List<User> getList() {
		return list;
	}
	public void setList(List<User> list) {
		this.list = list;
	}


	public String execute(){
		
		System.out.println(list);
		
		return NONE;
	}

	
}


<action name="list" class="com.hlg.data.ListAction"></action>


第三步在表单输入项里面写表达式

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

<form action="${pageContext.request.contextPath }/list.action" method="post">
	username:<input type="text" name="list[0].username"><br>
	password:<input type="text" name="list[0].password"><br>
	address:<input type="text" name="list[0].address"><br>
	<br>
	username:<input type="text" name="list[1].username"><br>
	password:<input type="text" name="list[1].password"><br>
	address:<input type="text" name="list[1].address"><br>
	<br>

	<input type="submit" value="提交">
</form>

</body>
</html>




封装数据到Map集合

第一步声明map集合

第二步生成getset方法

package com.hlg.data;

import java.util.Map;

import com.hlg.entity.User;
import com.opensymphony.xwork2.ActionSupport;
/**
 * 封装数据到list
 * @author Administrator
 *
 */
public class MapAction extends ActionSupport{

	private Map<String,User> map;

	public Map<String, User> getMap() {
		return map;
	}
	public void setMap(Map<String, User> map) {
		this.map = map;
	}


	public String execute(){
		
		System.out.println(map);
		
		return NONE;
	}

	
}


第三步在表单输入项的name属性值里面写表达式


/struts2_day02/WebContent/map.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

<form action="${pageContext.request.contextPath }/map.action" method="post">
	username:<input type="text" name="map['one'].username"><br>
	password:<input type="text" name="map['one'].password"><br>
	address:<input type="text" name="map['one'].address"><br>
	<br>
	username:<input type="text" name="map['abc'].username"><br>
	password:<input type="text" name="map['abc'].password"><br>
	address:<input type="text" name="map['abc'].address"><br>
	<br>

	<input type="submit" value="提交">
</form>

</body>
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值