1.使用Strut2的的集合对象:在jsp初始化action中的list然后提交到action

2.使用Struts标签,实现多个用户同时注册(注意属性配置文件)

3.pojo

  1. package com.sh.pojo;  
  2.   
  3. import java.util.Date;  
  4.   
  5. public class Register {  
  6. private String name;  
  7. private String pwd;  
  8. private int age;  
  9. private Date birthday;  
  10. private String address;  
  11.   
  12. //get set  
  13. }  
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

  1. package com.sh.action;  
  2.   
  3. import java.util.ArrayList;  
  4. import java.util.List;  
  5.   
  6. import com.opensymphony.xwork2.ActionSupport;  
  7. import com.sh.pojo.Register;  
  8.   
  9. public class RegisterAction extends ActionSupport {  
  10.   
  11.     private static final long serialVersionUID = 1L;  
  12.     private List<Register> registers;  
  13.     public List<Register> getRegisters() {  
  14.         return registers;  
  15.     }  
  16.     public void setRegisters(List<Register> registers) {  
  17.         this.registers = registers;  
  18.     }  
  19.     public String execute() throws Exception {  
  20.         return SUCCESS;  
  21.     }  
  22.       
  23. }  
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)

  1. Element_registers=com.sh.pojo.Register //Element_是固定的后面接action中的list集合变量名,后面是泛型中的对象类。  
Element_registers=com.sh.pojo.Register //Element_是固定的后面接action中的list集合变量名,后面是泛型中的对象类。

6.struts.xml

  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2. <!DOCTYPE struts PUBLIC  
  3.     "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"  
  4.     "http://struts.apache.org/dtds/struts-2.3.dtd">  
  5.   
  6. <struts>   
  7.      <!-- 定义国际化资源文件的基本名称 -->  
  8.     <constant name="struts.i18n.encoding" value="utf-8"/>  
  9.     <package name="default" extends="struts-default">  
  10.       
  11.         <!-- 使用list集合 -->  
  12.         <action name="registerAction" class="com.sh.action.RegisterAction">  
  13.             <result name="success">/success.jsp</result>    
  14.             <result name="input">/login.jsp</result>          
  15.         </action>  
  16.           
  17.         <!-- 使用Set集合 -->  
  18.         <action name="registerSetAction" class="com.sh.action.RegisterSetAction">  
  19.             <result name="success">/success1.jsp</result>    
  20.             <result name="input">/login3.jsp</result>         
  21.         </action>  
  22.         <!-- 使用 HashMap -->  
  23.         <action name="registerHashMapAction" class="com.sh.action.RegisterHashMapAction">  
  24.             <result name="success">/success3.jsp</result>    
  25.             <result name="input">/login3.jsp</result>         
  26.         </action>  
  27.           
  28.     </package>  
  29. </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 表达式

  1. <body>  
  2.     <s:form action="registerAction" method="post" theme="simple">  
  3.         <ul style="list-style:none; text-align: center;">  
  4.             <li style="float: left;width: 155px">用户名</li>  
  5.             <li style="float: left;width: 155px">密码</li>  
  6.             <li style="float: left;width: 155px">年龄</li>  
  7.             <li style="float: left;width: 155px">生日</li>  
  8.             <li style="float: left;width: 155px">地址</li>  
  9.           </ul>  
  10.           <div style="clear: both;"></div>  
  11. <!-- 手动声明一个 new int[4] 长度为4 的int 类型的数组-->  
  12.         <s:iterator value="new int[4]" status="st">  
  13.           <ul style="list-style:none;">  
  14.             <li style="float: left">  
  15.                 <s:textfield name="%{'registers['+#st.index+'].name'}" label="用户名"/>  
  16.             </li>  
  17.             <li style="float: left">  
  18.                 <s:password name="%{'registers['+#st.index+'].pwd'}" label="密码"/>  
  19.             </li>  
  20.             <li style="float: left">  
  21.                 <s:textfield name="%{'registers['+#st.index+'].age'}" label="年龄"/>  
  22.             </li>  
  23.             <li style="float: left">  
  24.                 <s:textfield name="%{'registers['+#st.index+'].birthday'}" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'});" label="生日"/>  
  25.             </li>  
  26.             <li>  
  27.                 <s:textfield name="%{'registers['+#st.index+'].address'}" label="地址"/>  
  28.             </li>  
  29.           </ul>  
  30.         </s:iterator>  
  31.        <div><s:submit value="submit"/></div>  
  32.     </s:form>  
  33.   </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 集合

  1. <body>  
  2.   <ul style="list-style:none; text-align: center;">  
  3.             <li style="float: left;width: 155px">用户名</li>  
  4.             <li style="float: left;width: 155px">密码</li>  
  5.             <li style="float: left;width: 155px">年龄</li>  
  6.             <li style="float: left;width: 155px">生日</li>  
  7.             <li style="float: left;width: 155px">地址</li>  
  8.           </ul>  
  9.           <div style="clear: both;"></div>  
  10.     <s:iterator value="registers" status="st">  
  11.          <ul style="list-style:none;">  
  12.             <li style="float: left;width: 155px;">  
  13.                 <s:property value="name"/>  
  14.             </li>  
  15.             <li style="float: left;width: 155px;">  
  16.                 <s:property value="pwd"/>  
  17.             </li>  
  18.             <li style="float: left;width: 155px;">  
  19.                 <s:property value="age"/>  
  20.             </li>  
  21.             <li style="float: left;width: 155px;">  
  22.                 <s:property value="birthday"/>  
  23.             </li>  
  24.             <li>  
  25.                 <s:property value="address"/>  
  26.             </li>  
  27.           </ul>  
  28.           <div></div>  
  29.     </s:iterator>  
  30.   </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

  1. <body>  
  2.     <form action="${pageContext.request.contextPath}/registerAction.action" method="post">  
  3.         <ul style="list-style:none; text-align: center;">  
  4.             <li style="float: left;width: 155px">用户名</li>  
  5.             <li style="float: left;width: 155px">密码</li>  
  6.             <li style="float: left;width: 155px">年龄</li>  
  7.             <li style="float: left;width: 155px">生日</li>  
  8.             <li style="float: left;width: 155px">地址</li>  
  9.           </ul>  
  10.           <div style="clear: both;"></div>  
  11. <!--注意这里 声明的时候和上面的不一样 new int[4] c标签识别不出来 ,识别的只有一个元素-->  
  12.         <c:forEach items="new int[]{0,0,0,0}" varStatus="st">  
  13.           <ul style="list-style:none;">  
  14.             <li style="float: left">  
  15.                 <input name="registers[${st.index}].name"/>  
  16.             </li>  
  17.             <li style="float: left">  
  18.                 <input name="registers[${st.index}].pwd" />  
  19.             </li>  
  20.             <li style="float: left">  
  21.                 <input name="registers[${st.index}].age"/>  
  22.             </li>  
  23.             <li style="float: left">  
  24.                 <input name="registers[${st.index}].birthday" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'});"/>  
  25.             </li>  
  26.             <li>  
  27.                 <input name="registers[${st.index}].address" />  
  28.             </li>  
  29.           </ul>  
  30.         </c:forEach>  
  31.        <div><input type="submit"/></div>  
  32.     </form>  
  33.   </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

  1. package com.sh.action;  
  2.   
  3. import java.util.LinkedHashSet;  
  4. import java.util.Set;  
  5.   
  6. import com.opensymphony.xwork2.ActionSupport;  
  7. import com.sh.pojo.Register;  
  8.   
  9. public class RegisterSetAction extends ActionSupport {  
  10.   
  11.     private Set<Register> registers=new LinkedHashSet<Register>();  
  12.   
  13.     public Set<Register> getRegisters() {  
  14.         return registers;  
  15.     }  
  16.   
  17.     public void setRegisters(Set<Register> registers) {  
  18.         this.registers = registers;  
  19.     }  
  20.   
  21.     @Override  
  22.     public String execute() throws Exception {  
  23.         // TODO Auto-generated method stub  
  24.         return SUCCESS;  
  25.     }     
  26.       
  27. }  
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

  1. KeyProperty_registers=name  //KeyProperty 如果是取 单个 就需要这个  
  2. Element_registers=com.sh.pojo.Register   
KeyProperty_registers=name  //KeyProperty 如果是取 单个 就需要这个Element_registers=com.sh.pojo.Register 

14.login3.jsp  (注意 初始化 set 的时候 采用 makeNew[] )

  1. <body>  
  2.     <s:form action="registerSetAction" method="post" theme="simple">  
  3.         <ul style="list-style:none; text-align: center;">  
  4.             <li style="float: left;width: 155px">用户名</li>  
  5.             <li style="float: left;width: 155px">密码</li>  
  6.             <li style="float: left;width: 155px">年龄</li>  
  7.             <li style="float: left;width: 155px">生日</li>  
  8.             <li style="float: left;width: 155px">地址</li>  
  9.           </ul>  
  10.           <div style="clear: both;"></div>  
  11.           <!-- 注意 使用了makeNew[] -->  
  12.         <s:iterator value="new int[4]" status="st">  
  13.           <ul style="list-style:none;">  
  14.             <li style="float: left">  
  15.                 <s:textfield name="%{'registers.makeNew['+#st.index+'].name'}" label="用户名"/>  
  16.             </li>  
  17.             <li style="float: left">  
  18.                 <s:password name="%{'registers.makeNew['+#st.index+'].pwd'}" label="密码"/>  
  19.             </li>  
  20.             <li style="float: left">  
  21.                 <s:textfield name="%{'registers.makeNew['+#st.index+'].age'}" label="年龄"/>  
  22.             </li>  
  23.             <li style="float: left">  
  24.                 <s:textfield name="%{'registers.makeNew['+#st.index+'].birthday'}" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'});" label="生日"/>  
  25.             </li>  
  26.             <li>  
  27.                 <s:textfield name="%{'registers.makeNew['+#st.index+'].address'}" label="地址"/>  
  28.             </li>  
  29.           </ul>  
  30.         </s:iterator>  
  31.        <div><s:submit value="submit"/></div>  
  32.     </s:form>  
  33.   </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 和获取 单个

  1. <body>  
  2.   <ul style="list-style:none; text-align: center;">  
  3.             <li style="float: left;width: 155px">用户名</li>  
  4.             <li style="float: left;width: 155px">密码</li>  
  5.             <li style="float: left;width: 155px">年龄</li>  
  6.             <li style="float: left;width: 155px">生日</li>  
  7.             <li style="float: left;width: 155px">地址</li>  
  8.           </ul>  
  9.           <div style="clear: both;"></div>  
  10.     <div>===========遍历所有的=========</div>  
  11.     <s:iterator value="registers" status="st">  
  12.          <ul style="list-style:none;">  
  13.             <li style="float: left;width: 155px;">  
  14.                 <s:property value="name"/>  
  15.             </li>  
  16.             <li style="float: left;width: 155px;">  
  17.                 <s:property value="pwd"/>  
  18.             </li>  
  19.             <li style="float: left;width: 155px;">  
  20.                 <s:property value="age"/>  
  21.             </li>  
  22.             <li style="float: left;width: 155px;">  
  23.                 <s:property value="birthday"/>  
  24.             </li>  
  25.             <li>  
  26.                 <s:property value="address"/>  
  27.             </li>  
  28.           </ul>  
  29.           <div></div>  
  30.     </s:iterator>  
  31.      <div>===========单独去其中的一个(知道其中的key wei admin)========</div>  
  32.      <ul style="list-style:none;">  
  33.             <li style="float: left;width: 155px;">  
  34.                 <s:property value="registers('admin').name"/>  
  35.             </li>  
  36.             <li style="float: left;width: 155px;">  
  37.                 <s:property value="registers('admin').pwd"/>  
  38.             </li>  
  39.             <li style="float: left;width: 155px;">  
  40.                 <s:property value="registers('admin').age"/>  
  41.             </li>  
  42.             <li style="float: left;width: 155px;">  
  43.                 <s:property value="registers('admin').birthday"/>  
  44.             </li>  
  45.             <li>  
  46.                 <s:property value="registers('admin').address"/>  
  47.             </li>  
  48.           </ul>  
  49.   </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

  1. package com.sh.action;  
  2.   
  3. import java.util.HashMap;  
  4. import java.util.Map;  
  5.   
  6. import com.opensymphony.xwork2.ActionSupport;  
  7. import com.sh.pojo.Register;  
  8.   
  9. public class RegisterHashMapAction extends ActionSupport {  
  10.   
  11.     private Map<String,Register> maps=new HashMap<String, Register>();  
  12.   
  13.     public Map<String, Register> getMaps() {  
  14.         return maps;  
  15.     }  
  16.   
  17.     public void setMaps(Map<String, Register> maps) {  
  18.         this.maps = maps;  
  19.     }  
  20.   
  21.     @Override  
  22.     public String execute() throws Exception {  
  23.         // TODO Auto-generated method stub  
  24.         return SUCCESS;  
  25.     }  
  26.       
  27.       
  28. }  
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

  1. Key_maps=java.lang.String   // Key_ 固定  后面为action的Map属性名  
  2. Element_maps=com.sh.pojo.Register  
Key_maps=java.lang.String   // Key_ 固定  后面为action的Map属性名Element_maps=com.sh.pojo.Register

19.login5.jsp

  1. <body>  
  2.     <s:form action="registerHashMapAction" method="post" theme="simple">  
  3.         <ul style="list-style:none; text-align: center;">  
  4.             <li style="float: left;width: 155px">用户名</li>  
  5.             <li style="float: left;width: 155px">密码</li>  
  6.             <li style="float: left;width: 155px">年龄</li>  
  7.             <li style="float: left;width: 155px">生日</li>  
  8.             <li style="float: left;width: 155px">地址</li>  
  9.           </ul>  
  10.           <div style="clear: both;"></div>  
  11.           <!-- 注意 【key】 中key 的取值类型和 配置文件中一直-->  
  12.         <s:iterator value="new int[4]" status="st">  
  13.           <ul style="list-style:none;">  
  14.             <li style="float: left">  
  15.                 <s:textfield name="%{'maps['+#st.index+'].name'}" label="用户名"/>  
  16.             </li>  
  17.             <li style="float: left">  
  18.                 <s:password name="%{'maps['+#st.index+'].pwd'}" label="密码"/>  
  19.             </li>  
  20.             <li style="float: left">  
  21.                 <s:textfield name="%{'maps['+#st.index+'].age'}" label="年龄"/>  
  22.             </li>  
  23.             <li style="float: left">  
  24.                 <s:textfield name="%{'maps['+#st.index+'].birthday'}" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'});" label="生日"/>  
  25.             </li>  
  26.             <li>  
  27.                 <s:textfield name="%{'maps['+#st.index+'].address'}" label="地址"/>  
  28.             </li>  
  29.           </ul>  
  30.         </s:iterator>  
  31.        <div><s:submit value="submit"/></div>  
  32.     </s:form>  
  33.   </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  和   取 单个

  1. <body>  
  2.   <ul style="list-style:none; text-align: center;">  
  3.             <li style="float: left;width: 155px">用户名</li>  
  4.             <li style="float: left;width: 155px">密码</li>  
  5.             <li style="float: left;width: 155px">年龄</li>  
  6.             <li style="float: left;width: 155px">生日</li>  
  7.             <li style="float: left;width: 155px">地址</li>  
  8.           </ul>  
  9.           <div style="clear: both;"></div>  
  10.     <div>===========遍历所有的=========</div>  
  11.     <s:iterator value="maps" status="st">  
  12.          <ul style="list-style:none;">  
  13.             <li style="float: left;width: 155px;">  
  14.                 <s:property value="value.name"/>  
  15.             </li>  
  16.             <li style="float: left;width: 155px;">  
  17.                 <s:property value="value.pwd"/>  
  18.             </li>  
  19.             <li style="float: left;width: 155px;">  
  20.                 <s:property value="value.age"/>  
  21.             </li>  
  22.             <li style="float: left;width: 155px;">  
  23.                 <s:property value="value.birthday"/>  
  24.             </li>  
  25.             <li>  
  26.                 <s:property value="value.address"/>  
  27.             </li>  
  28.           </ul>  
  29.           <div></div>  
  30.     </s:iterator>  
  31.      <div>===========单独去其中的一个= (知道其中的key=0)========</div>  
  32.      <ul style="list-style:none;">  
  33.             <li style="float: left;width: 155px;">  
  34.                 <s:property value="maps['0'].name"/>  
  35.             </li>  
  36.             <li style="float: left;width: 155px;">  
  37.                 <s:property value="maps['0'].pwd"/>  
  38.             </li>  
  39.             <li style="float: left;width: 155px;">  
  40.                 <s:property value="maps['0'].age"/>  
  41.             </li>  
  42.             <li style="float: left;width: 155px;">  
  43.                 <s:property value="maps['0'].birthday"/>  
  44.             </li>  
  45.             <li>  
  46.                 <s:property value="maps['0'].address"/>  
  47.             </li>  
  48.           </ul>  
  49.   </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技术网站的更多相关文章

  1. ASP.NET MVC 中将数据从View传递到控制器中的三种方法(表单数据绑定)

    http://www.cnblogs.com/zyqgold/archive/2010/11/22/1884779.html 在ASP.NET MVC框架中,将视图中的数据传递到控制器中,主要通过发送 ...

  2. 网站开发进阶(三十五)JSP页面中的pageEncoding和contentType两种属性

    JSP页面中的pageEncoding和contentType两种属性 本文介绍了在JSP页面中经常用的两种属性,分别是pageEncoding和contentType,希望对你有帮助,一起来看. 关 ...

  3. ASP.NET MVC中将数据从Controller传递到视图

    ASP.NET MVC中将数据从Controller传递到视图方法 1.ViewData ViewData的类型是字典数据,key-value 如:ViewData["Data"] ...

  4. struts2 jsp表单提交后保留表单中输入框中的值 下拉框select与input

    原文地址:struts2 jsp表单提交后保留表单中输入框中的值 下拉框select与input jsp页面 1     function dosearch() {2         if ($(&q ...

  5. java中将list、map对象写入文件

    链接地址:http://blog.sina.com.cn/s/blog_4a4f9fb50101p6jv.html     推荐:凤爪女瓜子男怪象该谁反思伦敦房价为什么持续暴涨 × wvqusrtg个 ...

  6. map 传递给函数的代价

    https://github.com/unknwon/the-way-to-go_ZH_CN/blob/master/eBook/08.1.md map 传递给函数的代价很小:在 32 位机器上占 4 ...

  7. (转) jsp页面 URL传中文参数到Action里面出现乱码

    jsp页面 URL传中文参数到Action里面出现乱码,方法如下: 第一种:在Action中用 new String(str.getBytes("ISO8859_1"), &quo ...

  8. javaweb学习总结(二十五)——jsp简单标签开发(一)

    一.简单标签(SimpleTag) 由于传统标签使用三个标签接口来完成不同的功能,显得过于繁琐,不利于标签技术的推广, SUN公司为降低标签技术的学习难度,在JSP 2.0中定义了一个更为简单.便于编 ...

  9. Struts2(十五)实现文件上传

    一.导入包 需要将commons-fileupload和commons-io包和struts包一起导入 实现步骤: 在Jsp页面实现客户端选择上传文件 配置Struts.xml,拦截器会自动接收上传的 ...

随机推荐

  1. Git Server和sourceTree客户端使用说明

    一.创建本地仓库 新建一个文件夹,命名为LocalRep,来作为本地仓库. 在终端 cd+拖拽文件夹到终端,打开文件夹在LocalRep目录下操作clone远程仓库到本地,指令如下所示(需根据实际情况 ...

  2. 1*Json对象声明简单,复合,对象数组

    //简单JSON对象 function btn1_click() { var json = { "id": 1001, "name": "张三&quo ...

  3. 详细的SQL中datediff用法

    DATEDIFF 函数 [日期和时间] 功能返回两个日期之间的间隔. 语法DATEDIFF ( date-part, date-expression-1, date-expression-2 ) da ...

  4. Java学习笔记之一

    1.对大小写敏感 2.class,类是构建所有Java应用程序和applet的构建块,Java应用程序中的全部内容都必须放置在类中. 3.类名,没有长度限制,必须以字母开头,可以使字母.数字.下划线的 ...

  5. mouse的各种事件

    IE测试对象为IE9,不全 mousemove(元素内部移动) 鼠标在元素内部移动时触发,只要鼠标移动,即使只是又移动了一个像素,也会触发,这就意味着短时间内会触发多次事件 支持情况: js onmo ...

  6. POI获取Excel列数和行数的方法

    //获取指定行,索引从0开始 hssfRow=hssfSheet.getRow(1); //获取指定列,索引从0开始 hssfCell=hssfRow.getCell((short)6);//获取总行 ...

  7. UVA - 1347 Tour(DP + 双调旅行商问题)

    题意:给出按照x坐标排序的n个点,让我们求出从最左端点到最右短点然后再回来,并且经过所有点且只经过一次的最短路径. 分析:这个题目刘汝佳的算法书上也有详解(就在基础dp那一段),具体思路如下:按照题目 ...

  8. HDU 5833 (2016大学生网络预选赛) Zhu and 772002(高斯消元求齐次方程的秩)

    网络预选赛的题目……比赛的时候没有做上,确实是没啥思路,只知道肯定是整数分解,然后乘起来素数的幂肯定是偶数,然后就不知道该怎么办了… 最后题目要求输出方案数,首先根据题目应该能写出如下齐次方程(从别人 ...

  9. Ubuntu下安装使用MongoDB

    安装 官网下载: https://www.mongodb.org/ 解压解包 重命名为mongodb 移动到/usr/local/目录下 创建连个软连接  ln -s /usr/local/mongo ...

  10. PAT (Advanced Level) 1095. Cars on Campus (30)

    模拟题.仔细一些即可. #include<cstdio> #include<cstring> #include<cmath> #include<algorit ...