首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Struts 交付对象集合List

2012-10-08 
Struts 提交对象集合Listpublic class TestBo implements Serializable {/** **/private static final lon

Struts 提交对象集合List
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:

?

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

代碼如下:

?

<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>

?

?

热点排行