Struts2中将表单数据封装到List和Map集合中
生活随笔
收集整理的這篇文章主要介紹了
Struts2中将表单数据封装到List和Map集合中
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
一.將表單數(shù)據(jù)封裝到Map集合中
1.創(chuàng)建MapAction類(lèi)
2.創(chuàng)建map.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head><title>Title</title> </head> <body><form action="${pageContext.request.contextPath}/map.action" method="post">username:<input name="map[0].username" type="text"><br>password:<input name="map[0].password" type="password"><br><br><br>username:<input name="map[1].username" type="text"><br>password:<input name="map[1].password" type="password"><br><input type="submit" name="Submit" value="提交"></form> </body> </html>3.表單頁(yè)面
在Struts.xml文件中中加入以下語(yǔ)句
**流程:**瀏覽器在解析表單數(shù)據(jù)會(huì)在MapAction實(shí)體類(lèi)中找到getMap方法獲取Map類(lèi)對(duì)象,然后在User實(shí)體類(lèi)中找到setUsername()等set方法將數(shù)據(jù)封裝到實(shí)體類(lèi)對(duì)象中
綜上所述:將數(shù)據(jù)封裝List集合同Map相同
總結(jié)
以上是生活随笔為你收集整理的Struts2中将表单数据封装到List和Map集合中的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 表达式封装和模型驱动封装的区别
- 下一篇: Struts2-day2总结