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,拦截器会自动接收上传的 ...
随机推荐
- hadoop native
http://blog.csdn.net/benben85/article/details/4161134 http://stackoverflow.com/questions/19943766/ha ...
- 打开另外一个App
/** * 打开一个app * * @param packageName * @param data * @return */ public static boolean lanuchApp(Cont ...
- 几种JAVA加密算法
转自:http://www.cnblogs.com/mycodelife/archive/2009/04/22/1441624.html
- 从今日起,我会把OpenGL红宝书上的例子用完整的代码形式写在我的博客中,
1.使用教程:OpenGL红宝书第8版 2.使用的库工具:GLEW和GLFW 3.使用的IDE:vs2012 4.说说目的:完整的看一遍OpenGL,加深印象并且熟练掌握运用OpenGL 5.欢迎有相 ...
- Spring Boot 系列教程6-全局异常处理
@ControllerAdvice源码 package org.springframework.web.bind.annotation; import java.lang.annotation.Ann ...
- 安卓常用 widget
验证码 public class SpinnerImg extends ImageView { /** * 完成选择后启动另外一个spinner */ private ItemListener ite ...
- alert()显示中文出现乱码
1.如果是外部调用 <script language="javascript" type="text/javascript" src="tswc ...
- Android中用友盟实现QQ的第三方登录
//首先应该去友盟的官网注册你的账号,创建一个应用,获得它的APPkey,也可以用它的API上的appkey,下载SDK,下面根据API文档一步步实现就行了. //下面是友盟的APi文档 1. 产品 ...
- CodeForces 678A Johny Likes Numbers
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
- UAC绕过思路(未完)
---恢复内容开始--- What is UAC?