Struts 提交对象集合List

Struts 提交对象集合List

javaBean

 

public class TestBo implements Serializable {  
  1.     /** 
  2.      *  
  3.      */  
  4.     private static final long serialVersionUID = 1L;  
  5.     private String name;  
  6.     private Long   age;  
  7.     private String address;  
  8.       
  9.     public String getAddress() {  
  10.         return address;  
  11.     }  
  12.     public void setAddress(String address) {  
  13.         this.address = address;  
  14.     }  
  15.     public Long getAge() {  
  16.         return age;  
  17.     }  
  18.     public void setAge(Long age) {  
  19.         this.age = age;  
  20.     }  
  21.     public String getName() {  
  22.         return name;  
  23.     }  
  24.     public void setName(String name) {  
  25.         this.name = name;  
  26.     }  
  27.       
  28.       
  29. }  
public class TestBo implements Serializable { /** * */ private static final long serialVersionUID = 1L; private String name; private Long age; private String address; public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public Long getAge() { return age; } public void setAge(Long age) { this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } }

 

 

action:

 

  1. public class TestAction extends ActionSupport {  
  2.     private List<TestBo> testList=new ArrayList<TestBo>();     
  3.        
  4.     public String execute() throws Exception {     
  5.         System.out.println("testList is "+testList);  
  6.         if(testList!=null && testList.size()>0){  
  7.             System.out.println("testList size is "+testList.size());  
  8.             for(int i=0;i<testList.size();i++){  
  9.                 TestBo bo=(TestBo)testList.get(i);  
  10.                 System.out.println("name is "+bo.getName()+",age is "+bo.getAge()+",address is "+bo.getAddress());  
  11.             }  
  12.         }  
  13.         return super.execute();     
  14.     }  
  15.   
  16.     public List<TestBo> getTestList() {  
  17.         return testList;  
  18.     }  
  19.   
  20.     public void setTestList(List<TestBo> testList) {  
  21.         this.testList = testList;  
  22.     }  
  23.       
  24.   
  25.   
  26. }  
public class TestAction extends ActionSupport { private List<TestBo> testList=new ArrayList<TestBo>(); public String execute() throws Exception { System.out.println("testList is "+testList); if(testList!=null && testList.size()>0){ System.out.println("testList size is "+testList.size()); for(int i=0;i<testList.size();i++){ TestBo bo=(TestBo)testList.get(i); System.out.println("name is "+bo.getName()+",age is "+bo.getAge()+",address is "+bo.getAddress()); } } return super.execute(); } public List<TestBo> getTestList() { return testList; } public void setTestList(List<TestBo> testList) { this.testList = testList; } }

 

 

關鍵一步是在action同一目錄加:SubmitTestBo-conversion.properties

properties 內容如下:

 

Element_testList=com.nmt.dates.datesTEST.TestBo
CreateIfNull_testList=true

 

 

前臺 jsp 我就沒有用動態新增,用靜態行demo

代碼如下:

 

  1. <FORM action='test.action' method='post'>  
  2.         <input type="text"  name="testList[0].name" value="名称1"/>    
  3.         <input type="text"  name="testList[0].age" value="50"/>    
  4.         <input type="text"  name="testList[0].address" value="地址111"/>    
  5.             
  6.         <input type="text"  name="testList[1].name" value="名称2"/>    
  7.         <input type="text"  name="testList[1].age" value="60"/>    
  8.         <input type="text"  name="testList[1].address" value="地址22"/>    
  9.           
  10.         <input type="text"  name="testList[2].name" value="001"/>    
  11.         <input type="text"  name="testList[2].age" value="80"/>    
  12.         <input type="text"  name="testList[2].address" value="地址33"/>    
  13.         <BUTTON type="submit" value="submit"></BUTTON>  
  14.           
  15. </FORM>  
<FORM action='test.action' method='post'> <input type="text" name="testList[0].name" value="名称1"/> <input type="text" name="testList[0].age" value="50"/> <input type="text" name="testList[0].address" value="地址111"/> <input type="text" name="testList[1].name" value="名称2"/> <input type="text" name="testList[1].age" value="60"/> <input type="text" name="testList[1].address" value="地址22"/> <input type="text" name="testList[2].name" value="001"/> <input type="text" name="testList[2].age" value="80"/> <input type="text" name="testList[2].address" value="地址33"/> <BUTTON type="submit" value="submit"></BUTTON> </FORM>

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值