Struts2中将表单数据封装到List和Map集合中
生活随笔
收集整理的這篇文章主要介紹了
Struts2中将表单数据封装到List和Map集合中
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一.將表單數據封裝到Map集合中
1.創建MapAction類
2.創建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.表單頁面
在Struts.xml文件中中加入以下語句
**流程:**瀏覽器在解析表單數據會在MapAction實體類中找到getMap方法獲取Map類對象,然后在User實體類中找到setUsername()等set方法將數據封裝到實體類對象中
綜上所述:將數據封裝List集合同Map相同
總結
以上是生活随笔為你收集整理的Struts2中将表单数据封装到List和Map集合中的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 表达式封装和模型驱动封装的区别
- 下一篇: Struts2-day2总结