Struts2 JSP中将list,set ,Map传递到Action然后遍历(三十五) - 雲淡風輕 - ITeye技术网站
1.使用Strut2的的集合对象:在jsp初始化action中的list然后提交到action
2.使用Struts标签,实现多个用户同时注册(注意属性配置文件)
3.pojo
- package com.sh.pojo;
- import java.util.Date;
- public class Register {
- private String name;
- private String pwd;
- private int age;
- private Date birthday;
- private String address;
- //get set
- }
package com.sh.pojo;import java.util.Date;public class Register {private String name;private String pwd;private int age;private Date birthday;private String address;//get set}
4.action
- package com.sh.action;
- import java.util.ArrayList;
- import java.util.List;
- import com.opensymphony.xwork2.ActionSupport;
- import com.sh.pojo.Register;
- public class RegisterAction extends ActionSupport {
- private static final long serialVersionUID = 1L;
- private List<Register> registers;
- public List<Register> getRegisters() {
- return registers;
- }
- public void setRegisters(List<Register> registers) {
- this.registers = registers;
- }
- public String execute() throws Exception {
- return SUCCESS;
- }
- }
package com.sh.action;import java.util.ArrayList;import java.util.List;import com.opensymphony.xwork2.ActionSupport;import com.sh.pojo.Register;public class RegisterAction extends ActionSupport { private static final long serialVersionUID = 1L; private List<Register> registers; public List<Register> getRegisters() { return registers; } public void setRegisters(List<Register> registers) { this.registers = registers; } public String execute() throws Exception { return SUCCESS; } }
5.RegisterAction-conversion.properties(配置action中list的泛型对象,放在action同一目录下,属性文件的命名为:actionName-version.properties)
- Element_registers=com.sh.pojo.Register //Element_是固定的后面接action中的list集合变量名,后面是泛型中的对象类。
Element_registers=com.sh.pojo.Register //Element_是固定的后面接action中的list集合变量名,后面是泛型中的对象类。
6.struts.xml
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE struts PUBLIC
- "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
- "http://struts.apache.org/dtds/struts-2.3.dtd">
- <struts>
- <!-- 定义国际化资源文件的基本名称 -->
- <constant name="struts.i18n.encoding" value="utf-8"/>
- <package name="default" extends="struts-default">
- <!-- 使用list集合 -->
- <action name="registerAction" class="com.sh.action.RegisterAction">
- <result name="success">/success.jsp</result>
- <result name="input">/login.jsp</result>
- </action>
- <!-- 使用Set集合 -->
- <action name="registerSetAction" class="com.sh.action.RegisterSetAction">
- <result name="success">/success1.jsp</result>
- <result name="input">/login3.jsp</result>
- </action>
- <!-- 使用 HashMap -->
- <action name="registerHashMapAction" class="com.sh.action.RegisterHashMapAction">
- <result name="success">/success3.jsp</result>
- <result name="input">/login3.jsp</result>
- </action>
- </package>
- </struts>
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"><struts> <!-- 定义国际化资源文件的基本名称 --> <constant name="struts.i18n.encoding" value="utf-8"/> <package name="default" extends="struts-default"> <!-- 使用list集合 --> <action name="registerAction" class="com.sh.action.RegisterAction"> <result name="success">/success.jsp</result> <result name="input">/login.jsp</result> </action> <!-- 使用Set集合 --> <action name="registerSetAction" class="com.sh.action.RegisterSetAction"> <result name="success">/success1.jsp</result> <result name="input">/login3.jsp</result> </action> <!-- 使用 HashMap --> <action name="registerHashMapAction" class="com.sh.action.RegisterHashMapAction"> <result name="success">/success3.jsp</result> <result name="input">/login3.jsp</result> </action> </package></struts>
7.login.jsp 使用 struts2标签 和 OGNL 表达式
- <body>
- <s:form action="registerAction" method="post" theme="simple">
- <ul style="list-style:none; text-align: center;">
- <li style="float: left;width: 155px">用户名</li>
- <li style="float: left;width: 155px">密码</li>
- <li style="float: left;width: 155px">年龄</li>
- <li style="float: left;width: 155px">生日</li>
- <li style="float: left;width: 155px">地址</li>
- </ul>
- <div style="clear: both;"></div>
- <!-- 手动声明一个 new int[4] 长度为4 的int 类型的数组-->
- <s:iterator value="new int[4]" status="st">
- <ul style="list-style:none;">
- <li style="float: left">
- <s:textfield name="%{'registers['+#st.index+'].name'}" label="用户名"/>
- </li>
- <li style="float: left">
- <s:password name="%{'registers['+#st.index+'].pwd'}" label="密码"/>
- </li>
- <li style="float: left">
- <s:textfield name="%{'registers['+#st.index+'].age'}" label="年龄"/>
- </li>
- <li style="float: left">
- <s:textfield name="%{'registers['+#st.index+'].birthday'}" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'});" label="生日"/>
- </li>
- <li>
- <s:textfield name="%{'registers['+#st.index+'].address'}" label="地址"/>
- </li>
- </ul>
- </s:iterator>
- <div><s:submit value="submit"/></div>
- </s:form>
- </body>
<body> <s:form action="registerAction" method="post" theme="simple"> <ul style="list-style:none; text-align: center;"> <li style="float: left;width: 155px">用户名</li> <li style="float: left;width: 155px">密码</li> <li style="float: left;width: 155px">年龄</li> <li style="float: left;width: 155px">生日</li> <li style="float: left;width: 155px">地址</li> </ul> <div style="clear: both;"></div><!-- 手动声明一个 new int[4] 长度为4 的int 类型的数组--> <s:iterator value="new int[4]" status="st"> <ul style="list-style:none;"> <li style="float: left"> <s:textfield name="%{'registers['+#st.index+'].name'}" label="用户名"/> </li> <li style="float: left"> <s:password name="%{'registers['+#st.index+'].pwd'}" label="密码"/> </li> <li style="float: left"> <s:textfield name="%{'registers['+#st.index+'].age'}" label="年龄"/> </li> <li style="float: left"> <s:textfield name="%{'registers['+#st.index+'].birthday'}" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'});" label="生日"/> </li> <li> <s:textfield name="%{'registers['+#st.index+'].address'}" label="地址"/> </li> </ul> </s:iterator> <div><s:submit value="submit"/></div> </s:form> </body>
8.success.jsp 循环遍历 list 集合
- <body>
- <ul style="list-style:none; text-align: center;">
- <li style="float: left;width: 155px">用户名</li>
- <li style="float: left;width: 155px">密码</li>
- <li style="float: left;width: 155px">年龄</li>
- <li style="float: left;width: 155px">生日</li>
- <li style="float: left;width: 155px">地址</li>
- </ul>
- <div style="clear: both;"></div>
- <s:iterator value="registers" status="st">
- <ul style="list-style:none;">
- <li style="float: left;width: 155px;">
- <s:property value="name"/>
- </li>
- <li style="float: left;width: 155px;">
- <s:property value="pwd"/>
- </li>
- <li style="float: left;width: 155px;">
- <s:property value="age"/>
- </li>
- <li style="float: left;width: 155px;">
- <s:property value="birthday"/>
- </li>
- <li>
- <s:property value="address"/>
- </li>
- </ul>
- <div></div>
- </s:iterator>
- </body>
<body> <ul style="list-style:none; text-align: center;"> <li style="float: left;width: 155px">用户名</li> <li style="float: left;width: 155px">密码</li> <li style="float: left;width: 155px">年龄</li> <li style="float: left;width: 155px">生日</li> <li style="float: left;width: 155px">地址</li> </ul> <div style="clear: both;"></div> <s:iterator value="registers" status="st"> <ul style="list-style:none;"> <li style="float: left;width: 155px;"> <s:property value="name"/> </li> <li style="float: left;width: 155px;"> <s:property value="pwd"/> </li> <li style="float: left;width: 155px;"> <s:property value="age"/> </li> <li style="float: left;width: 155px;"> <s:property value="birthday"/> </li> <li> <s:property value="address"/> </li> </ul> <div></div> </s:iterator> </body>
9.访问
--localhost:8080/Struts2_CollectConversion/login.jsp
填上信息后提交就可以看到成功页面的循环的输出
10.使用 jstl c 标签 和 EL 表达式 实现上面的 批量注册 (注意 数组初始化)
long1.jsp
- <body>
- <form action="${pageContext.request.contextPath}/registerAction.action" method="post">
- <ul style="list-style:none; text-align: center;">
- <li style="float: left;width: 155px">用户名</li>
- <li style="float: left;width: 155px">密码</li>
- <li style="float: left;width: 155px">年龄</li>
- <li style="float: left;width: 155px">生日</li>
- <li style="float: left;width: 155px">地址</li>
- </ul>
- <div style="clear: both;"></div>
- <!--注意这里 声明的时候和上面的不一样 new int[4] c标签识别不出来 ,识别的只有一个元素-->
- <c:forEach items="new int[]{0,0,0,0}" varStatus="st">
- <ul style="list-style:none;">
- <li style="float: left">
- <input name="registers[${st.index}].name"/>
- </li>
- <li style="float: left">
- <input name="registers[${st.index}].pwd" />
- </li>
- <li style="float: left">
- <input name="registers[${st.index}].age"/>
- </li>
- <li style="float: left">
- <input name="registers[${st.index}].birthday" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'});"/>
- </li>
- <li>
- <input name="registers[${st.index}].address" />
- </li>
- </ul>
- </c:forEach>
- <div><input type="submit"/></div>
- </form>
- </body>
<body> <form action="${pageContext.request.contextPath}/registerAction.action" method="post"> <ul style="list-style:none; text-align: center;"> <li style="float: left;width: 155px">用户名</li> <li style="float: left;width: 155px">密码</li> <li style="float: left;width: 155px">年龄</li> <li style="float: left;width: 155px">生日</li> <li style="float: left;width: 155px">地址</li> </ul> <div style="clear: both;"></div><!--注意这里 声明的时候和上面的不一样 new int[4] c标签识别不出来 ,识别的只有一个元素--> <c:forEach items="new int[]{0,0,0,0}" varStatus="st"> <ul style="list-style:none;"> <li style="float: left"> <input name="registers[${st.index}].name"/> </li> <li style="float: left"> <input name="registers[${st.index}].pwd" /> </li> <li style="float: left"> <input name="registers[${st.index}].age"/> </li> <li style="float: left"> <input name="registers[${st.index}].birthday" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'});"/> </li> <li> <input name="registers[${st.index}].address" /> </li> </ul> </c:forEach> <div><input type="submit"/></div> </form> </body>
11.访问
--localhost:8080/Struts2_CollectConversion/login1.jsp
填上信息后和上面的一样。
---------------Set----------------
12.使用Strutgs2的 Set 类型. 遍历所有 和 取其中一个
action
- package com.sh.action;
- import java.util.LinkedHashSet;
- import java.util.Set;
- import com.opensymphony.xwork2.ActionSupport;
- import com.sh.pojo.Register;
- public class RegisterSetAction extends ActionSupport {
- private Set<Register> registers=new LinkedHashSet<Register>();
- public Set<Register> getRegisters() {
- return registers;
- }
- public void setRegisters(Set<Register> registers) {
- this.registers = registers;
- }
- @Override
- public String execute() throws Exception {
- // TODO Auto-generated method stub
- return SUCCESS;
- }
- }
package com.sh.action;import java.util.LinkedHashSet;import java.util.Set;import com.opensymphony.xwork2.ActionSupport;import com.sh.pojo.Register;public class RegisterSetAction extends ActionSupport { private Set<Register> registers=new LinkedHashSet<Register>(); public Set<Register> getRegisters() { return registers; } public void setRegisters(Set<Register> registers) { this.registers = registers; } @Override public String execute() throws Exception { // TODO Auto-generated method stub return SUCCESS; } }
13.RegisterSetAction-conversion.properties
- KeyProperty_registers=name //KeyProperty 如果是取 单个 就需要这个
- Element_registers=com.sh.pojo.Register
KeyProperty_registers=name //KeyProperty 如果是取 单个 就需要这个Element_registers=com.sh.pojo.Register
14.login3.jsp (注意 初始化 set 的时候 采用 makeNew[] )
- <body>
- <s:form action="registerSetAction" method="post" theme="simple">
- <ul style="list-style:none; text-align: center;">
- <li style="float: left;width: 155px">用户名</li>
- <li style="float: left;width: 155px">密码</li>
- <li style="float: left;width: 155px">年龄</li>
- <li style="float: left;width: 155px">生日</li>
- <li style="float: left;width: 155px">地址</li>
- </ul>
- <div style="clear: both;"></div>
- <!-- 注意 使用了makeNew[] -->
- <s:iterator value="new int[4]" status="st">
- <ul style="list-style:none;">
- <li style="float: left">
- <s:textfield name="%{'registers.makeNew['+#st.index+'].name'}" label="用户名"/>
- </li>
- <li style="float: left">
- <s:password name="%{'registers.makeNew['+#st.index+'].pwd'}" label="密码"/>
- </li>
- <li style="float: left">
- <s:textfield name="%{'registers.makeNew['+#st.index+'].age'}" label="年龄"/>
- </li>
- <li style="float: left">
- <s:textfield name="%{'registers.makeNew['+#st.index+'].birthday'}" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'});" label="生日"/>
- </li>
- <li>
- <s:textfield name="%{'registers.makeNew['+#st.index+'].address'}" label="地址"/>
- </li>
- </ul>
- </s:iterator>
- <div><s:submit value="submit"/></div>
- </s:form>
- </body>
<body> <s:form action="registerSetAction" method="post" theme="simple"> <ul style="list-style:none; text-align: center;"> <li style="float: left;width: 155px">用户名</li> <li style="float: left;width: 155px">密码</li> <li style="float: left;width: 155px">年龄</li> <li style="float: left;width: 155px">生日</li> <li style="float: left;width: 155px">地址</li> </ul> <div style="clear: both;"></div> <!-- 注意 使用了makeNew[] --> <s:iterator value="new int[4]" status="st"> <ul style="list-style:none;"> <li style="float: left"> <s:textfield name="%{'registers.makeNew['+#st.index+'].name'}" label="用户名"/> </li> <li style="float: left"> <s:password name="%{'registers.makeNew['+#st.index+'].pwd'}" label="密码"/> </li> <li style="float: left"> <s:textfield name="%{'registers.makeNew['+#st.index+'].age'}" label="年龄"/> </li> <li style="float: left"> <s:textfield name="%{'registers.makeNew['+#st.index+'].birthday'}" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'});" label="生日"/> </li> <li> <s:textfield name="%{'registers.makeNew['+#st.index+'].address'}" label="地址"/> </li> </ul> </s:iterator> <div><s:submit value="submit"/></div> </s:form> </body>
15.success2.jsp 遍历 Set 和获取 单个
- <body>
- <ul style="list-style:none; text-align: center;">
- <li style="float: left;width: 155px">用户名</li>
- <li style="float: left;width: 155px">密码</li>
- <li style="float: left;width: 155px">年龄</li>
- <li style="float: left;width: 155px">生日</li>
- <li style="float: left;width: 155px">地址</li>
- </ul>
- <div style="clear: both;"></div>
- <div>===========遍历所有的=========</div>
- <s:iterator value="registers" status="st">
- <ul style="list-style:none;">
- <li style="float: left;width: 155px;">
- <s:property value="name"/>
- </li>
- <li style="float: left;width: 155px;">
- <s:property value="pwd"/>
- </li>
- <li style="float: left;width: 155px;">
- <s:property value="age"/>
- </li>
- <li style="float: left;width: 155px;">
- <s:property value="birthday"/>
- </li>
- <li>
- <s:property value="address"/>
- </li>
- </ul>
- <div></div>
- </s:iterator>
- <div>===========单独去其中的一个(知道其中的key wei admin)========</div>
- <ul style="list-style:none;">
- <li style="float: left;width: 155px;">
- <s:property value="registers('admin').name"/>
- </li>
- <li style="float: left;width: 155px;">
- <s:property value="registers('admin').pwd"/>
- </li>
- <li style="float: left;width: 155px;">
- <s:property value="registers('admin').age"/>
- </li>
- <li style="float: left;width: 155px;">
- <s:property value="registers('admin').birthday"/>
- </li>
- <li>
- <s:property value="registers('admin').address"/>
- </li>
- </ul>
- </body>
<body> <ul style="list-style:none; text-align: center;"> <li style="float: left;width: 155px">用户名</li> <li style="float: left;width: 155px">密码</li> <li style="float: left;width: 155px">年龄</li> <li style="float: left;width: 155px">生日</li> <li style="float: left;width: 155px">地址</li> </ul> <div style="clear: both;"></div> <div>===========遍历所有的=========</div> <s:iterator value="registers" status="st"> <ul style="list-style:none;"> <li style="float: left;width: 155px;"> <s:property value="name"/> </li> <li style="float: left;width: 155px;"> <s:property value="pwd"/> </li> <li style="float: left;width: 155px;"> <s:property value="age"/> </li> <li style="float: left;width: 155px;"> <s:property value="birthday"/> </li> <li> <s:property value="address"/> </li> </ul> <div></div> </s:iterator> <div>===========单独去其中的一个(知道其中的key wei admin)========</div> <ul style="list-style:none;"> <li style="float: left;width: 155px;"> <s:property value="registers('admin').name"/> </li> <li style="float: left;width: 155px;"> <s:property value="registers('admin').pwd"/> </li> <li style="float: left;width: 155px;"> <s:property value="registers('admin').age"/> </li> <li style="float: left;width: 155px;"> <s:property value="registers('admin').birthday"/> </li> <li> <s:property value="registers('admin').address"/> </li> </ul> </body>
16.访问
--http://localhost:8080/Struts2_CollectConversion/login3.jsp
填写信息后 就会到成功页面 看到遍历所有 和 取单个
---------------Map----------------
17.使用 Strut2的 Map 类型
action
- package com.sh.action;
- import java.util.HashMap;
- import java.util.Map;
- import com.opensymphony.xwork2.ActionSupport;
- import com.sh.pojo.Register;
- public class RegisterHashMapAction extends ActionSupport {
- private Map<String,Register> maps=new HashMap<String, Register>();
- public Map<String, Register> getMaps() {
- return maps;
- }
- public void setMaps(Map<String, Register> maps) {
- this.maps = maps;
- }
- @Override
- public String execute() throws Exception {
- // TODO Auto-generated method stub
- return SUCCESS;
- }
- }
package com.sh.action;import java.util.HashMap;import java.util.Map;import com.opensymphony.xwork2.ActionSupport;import com.sh.pojo.Register;public class RegisterHashMapAction extends ActionSupport { private Map<String,Register> maps=new HashMap<String, Register>(); public Map<String, Register> getMaps() { return maps; } public void setMaps(Map<String, Register> maps) { this.maps = maps; } @Override public String execute() throws Exception { // TODO Auto-generated method stub return SUCCESS; } }
18.属性配置文件 RegisterHashMapAction-conversion.properties
- Key_maps=java.lang.String // Key_ 固定 后面为action的Map属性名
- Element_maps=com.sh.pojo.Register
Key_maps=java.lang.String // Key_ 固定 后面为action的Map属性名Element_maps=com.sh.pojo.Register
19.login5.jsp
- <body>
- <s:form action="registerHashMapAction" method="post" theme="simple">
- <ul style="list-style:none; text-align: center;">
- <li style="float: left;width: 155px">用户名</li>
- <li style="float: left;width: 155px">密码</li>
- <li style="float: left;width: 155px">年龄</li>
- <li style="float: left;width: 155px">生日</li>
- <li style="float: left;width: 155px">地址</li>
- </ul>
- <div style="clear: both;"></div>
- <!-- 注意 【key】 中key 的取值类型和 配置文件中一直-->
- <s:iterator value="new int[4]" status="st">
- <ul style="list-style:none;">
- <li style="float: left">
- <s:textfield name="%{'maps['+#st.index+'].name'}" label="用户名"/>
- </li>
- <li style="float: left">
- <s:password name="%{'maps['+#st.index+'].pwd'}" label="密码"/>
- </li>
- <li style="float: left">
- <s:textfield name="%{'maps['+#st.index+'].age'}" label="年龄"/>
- </li>
- <li style="float: left">
- <s:textfield name="%{'maps['+#st.index+'].birthday'}" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'});" label="生日"/>
- </li>
- <li>
- <s:textfield name="%{'maps['+#st.index+'].address'}" label="地址"/>
- </li>
- </ul>
- </s:iterator>
- <div><s:submit value="submit"/></div>
- </s:form>
- </body>
<body> <s:form action="registerHashMapAction" method="post" theme="simple"> <ul style="list-style:none; text-align: center;"> <li style="float: left;width: 155px">用户名</li> <li style="float: left;width: 155px">密码</li> <li style="float: left;width: 155px">年龄</li> <li style="float: left;width: 155px">生日</li> <li style="float: left;width: 155px">地址</li> </ul> <div style="clear: both;"></div> <!-- 注意 【key】 中key 的取值类型和 配置文件中一直--> <s:iterator value="new int[4]" status="st"> <ul style="list-style:none;"> <li style="float: left"> <s:textfield name="%{'maps['+#st.index+'].name'}" label="用户名"/> </li> <li style="float: left"> <s:password name="%{'maps['+#st.index+'].pwd'}" label="密码"/> </li> <li style="float: left"> <s:textfield name="%{'maps['+#st.index+'].age'}" label="年龄"/> </li> <li style="float: left"> <s:textfield name="%{'maps['+#st.index+'].birthday'}" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'});" label="生日"/> </li> <li> <s:textfield name="%{'maps['+#st.index+'].address'}" label="地址"/> </li> </ul> </s:iterator> <div><s:submit value="submit"/></div> </s:form> </body>
20 .success3.jsp 遍历 Map 和 取 单个
- <body>
- <ul style="list-style:none; text-align: center;">
- <li style="float: left;width: 155px">用户名</li>
- <li style="float: left;width: 155px">密码</li>
- <li style="float: left;width: 155px">年龄</li>
- <li style="float: left;width: 155px">生日</li>
- <li style="float: left;width: 155px">地址</li>
- </ul>
- <div style="clear: both;"></div>
- <div>===========遍历所有的=========</div>
- <s:iterator value="maps" status="st">
- <ul style="list-style:none;">
- <li style="float: left;width: 155px;">
- <s:property value="value.name"/>
- </li>
- <li style="float: left;width: 155px;">
- <s:property value="value.pwd"/>
- </li>
- <li style="float: left;width: 155px;">
- <s:property value="value.age"/>
- </li>
- <li style="float: left;width: 155px;">
- <s:property value="value.birthday"/>
- </li>
- <li>
- <s:property value="value.address"/>
- </li>
- </ul>
- <div></div>
- </s:iterator>
- <div>===========单独去其中的一个= (知道其中的key=0)========</div>
- <ul style="list-style:none;">
- <li style="float: left;width: 155px;">
- <s:property value="maps['0'].name"/>
- </li>
- <li style="float: left;width: 155px;">
- <s:property value="maps['0'].pwd"/>
- </li>
- <li style="float: left;width: 155px;">
- <s:property value="maps['0'].age"/>
- </li>
- <li style="float: left;width: 155px;">
- <s:property value="maps['0'].birthday"/>
- </li>
- <li>
- <s:property value="maps['0'].address"/>
- </li>
- </ul>
- </body>
<body> <ul style="list-style:none; text-align: center;"> <li style="float: left;width: 155px">用户名</li> <li style="float: left;width: 155px">密码</li> <li style="float: left;width: 155px">年龄</li> <li style="float: left;width: 155px">生日</li> <li style="float: left;width: 155px">地址</li> </ul> <div style="clear: both;"></div> <div>===========遍历所有的=========</div> <s:iterator value="maps" status="st"> <ul style="list-style:none;"> <li style="float: left;width: 155px;"> <s:property value="value.name"/> </li> <li style="float: left;width: 155px;"> <s:property value="value.pwd"/> </li> <li style="float: left;width: 155px;"> <s:property value="value.age"/> </li> <li style="float: left;width: 155px;"> <s:property value="value.birthday"/> </li> <li> <s:property value="value.address"/> </li> </ul> <div></div> </s:iterator> <div>===========单独去其中的一个= (知道其中的key=0)========</div> <ul style="list-style:none;"> <li style="float: left;width: 155px;"> <s:property value="maps['0'].name"/> </li> <li style="float: left;width: 155px;"> <s:property value="maps['0'].pwd"/> </li> <li style="float: left;width: 155px;"> <s:property value="maps['0'].age"/> </li> <li style="float: left;width: 155px;"> <s:property value="maps['0'].birthday"/> </li> <li> <s:property value="maps['0'].address"/> </li> </ul> </body>
21.访问
--http://localhost:8080/Struts2_CollectConversion/login5.jsp
填写信息就可以看到结果了
注意 action中 set 和hashmap 都要 初始化 和 有 get 和set 方法
Struts2 JSP中将list,set ,Map传递到Action然后遍历(三十五) - 雲淡風輕 - ITeye技术网站的更多相关文章
- ASP.NET MVC 中将数据从View传递到控制器中的三种方法(表单数据绑定)
http://www.cnblogs.com/zyqgold/archive/2010/11/22/1884779.html 在ASP.NET MVC框架中,将视图中的数据传递到控制器中,主要通过发送 ...
- 网站开发进阶(三十五)JSP页面中的pageEncoding和contentType两种属性
JSP页面中的pageEncoding和contentType两种属性 本文介绍了在JSP页面中经常用的两种属性,分别是pageEncoding和contentType,希望对你有帮助,一起来看. 关 ...
- ASP.NET MVC中将数据从Controller传递到视图
ASP.NET MVC中将数据从Controller传递到视图方法 1.ViewData ViewData的类型是字典数据,key-value 如:ViewData["Data"] ...
- struts2 jsp表单提交后保留表单中输入框中的值 下拉框select与input
原文地址:struts2 jsp表单提交后保留表单中输入框中的值 下拉框select与input jsp页面 1 function dosearch() {2 if ($(&q ...
- java中将list、map对象写入文件
链接地址:http://blog.sina.com.cn/s/blog_4a4f9fb50101p6jv.html 推荐:凤爪女瓜子男怪象该谁反思伦敦房价为什么持续暴涨 × wvqusrtg个 ...
- map 传递给函数的代价
https://github.com/unknwon/the-way-to-go_ZH_CN/blob/master/eBook/08.1.md map 传递给函数的代价很小:在 32 位机器上占 4 ...
- (转) jsp页面 URL传中文参数到Action里面出现乱码
jsp页面 URL传中文参数到Action里面出现乱码,方法如下: 第一种:在Action中用 new String(str.getBytes("ISO8859_1"), &quo ...
- javaweb学习总结(二十五)——jsp简单标签开发(一)
一.简单标签(SimpleTag) 由于传统标签使用三个标签接口来完成不同的功能,显得过于繁琐,不利于标签技术的推广, SUN公司为降低标签技术的学习难度,在JSP 2.0中定义了一个更为简单.便于编 ...
- Struts2(十五)实现文件上传
一.导入包 需要将commons-fileupload和commons-io包和struts包一起导入 实现步骤: 在Jsp页面实现客户端选择上传文件 配置Struts.xml,拦截器会自动接收上传的 ...
随机推荐
- Git Server和sourceTree客户端使用说明
一.创建本地仓库 新建一个文件夹,命名为LocalRep,来作为本地仓库. 在终端 cd+拖拽文件夹到终端,打开文件夹在LocalRep目录下操作clone远程仓库到本地,指令如下所示(需根据实际情况 ...
- 1*Json对象声明简单,复合,对象数组
//简单JSON对象 function btn1_click() { var json = { "id": 1001, "name": "张三&quo ...
- 详细的SQL中datediff用法
DATEDIFF 函数 [日期和时间] 功能返回两个日期之间的间隔. 语法DATEDIFF ( date-part, date-expression-1, date-expression-2 ) da ...
- Java学习笔记之一
1.对大小写敏感 2.class,类是构建所有Java应用程序和applet的构建块,Java应用程序中的全部内容都必须放置在类中. 3.类名,没有长度限制,必须以字母开头,可以使字母.数字.下划线的 ...
- mouse的各种事件
IE测试对象为IE9,不全 mousemove(元素内部移动) 鼠标在元素内部移动时触发,只要鼠标移动,即使只是又移动了一个像素,也会触发,这就意味着短时间内会触发多次事件 支持情况: js onmo ...
- POI获取Excel列数和行数的方法
//获取指定行,索引从0开始 hssfRow=hssfSheet.getRow(1); //获取指定列,索引从0开始 hssfCell=hssfRow.getCell((short)6);//获取总行 ...
- UVA - 1347 Tour(DP + 双调旅行商问题)
题意:给出按照x坐标排序的n个点,让我们求出从最左端点到最右短点然后再回来,并且经过所有点且只经过一次的最短路径. 分析:这个题目刘汝佳的算法书上也有详解(就在基础dp那一段),具体思路如下:按照题目 ...
- HDU 5833 (2016大学生网络预选赛) Zhu and 772002(高斯消元求齐次方程的秩)
网络预选赛的题目……比赛的时候没有做上,确实是没啥思路,只知道肯定是整数分解,然后乘起来素数的幂肯定是偶数,然后就不知道该怎么办了… 最后题目要求输出方案数,首先根据题目应该能写出如下齐次方程(从别人 ...
- Ubuntu下安装使用MongoDB
安装 官网下载: https://www.mongodb.org/ 解压解包 重命名为mongodb 移动到/usr/local/目录下 创建连个软连接 ln -s /usr/local/mongo ...
- PAT (Advanced Level) 1095. Cars on Campus (30)
模拟题.仔细一些即可. #include<cstdio> #include<cstring> #include<cmath> #include<algorit ...