急啊,struts2怎么从jsp向action传递list啊,我在做一个报名的系统,一个表单要提交多个人的信息

网上(以下)我都试了,不行……struts2类型转换错误
public class StudentAction{
private String sname;
private int tel; //我换成Integer也不行
pirvate List<Student> list;
}
然后我在界面
<input name="list[0].sname"/>
<input name="list[0].tel"/> //就int不行,它说我给tel的setter提供了一个String类型,但是我换成integer,也重载了setter(String) 也不行
那个高手知道怎么从jsp向action传递list,虚心学习,命苦学生程序员啊,还要学习,真心求做过类似项目的人求指导! 企VV鹅:463068132

这个我以经总结过了, 有不明白的问我 85785053 QQ

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-04-16
你好,给你这个例子,你读一读:
public class Person {
int id;
String name;
int age;
float height;
}
这是一个POJO,getter和setting省略了。
action中可以这样使用:
public class MyAction {
public List getPeopleList() { … }
public void setPeopleList( List peopleList ) { … }

}
在我们使用Person类之前,需要添加一个配置文件,MyAction-conversion.properties,把这个文件和MyAction放在一起。
这个文件里只有一行内容:
Element_peopleList=Person
前缀Element_是一个常量,表明等号左边的表达式中跟在这个常量后面的是Action类中一个List类型的字段名。
等号右边的表达式是全类名(包含package)
下面是一个页面的代码片段:
<s:form action="update" method="post" >
<s:iterator value="peopleList" status="stat">
<s:hidden
name="peopleList[%{#stat.index}].id"
value="%{peopleList[#stat.index].id}"/>
<s:textfield label="Name"
name="peopleList[%{#stat.index}].name"
value="%{peopleList[#stat.index].name}"/>
<s:textfield label="Age"
name="peopleList[%{#stat.index}].age"
value="%{peopleList[#stat.index].age}" />
<s:textfield label="Height"
name="peopleList[%{#stat.index}].height"
value="%{peopleList[#stat.index].height}"/>
<br/>
s:iterator>
<s:submit value="Update"/>
s:form>
使用这段代码,Struts2会创建一个Person类的ArrayList,并且用setPersonList这个方法把页面表格中的值传递回Action。
如果你是想从用户界面中动态创建列表值,需要允许Struts2给列表中类的实例。那么在配置文件MyAction-conversion.properties中添加一行:
CreateIfNull_peopleList = true
第2个回答  2013-04-16
jsp向action传递list藐视不是你这样写的
相似回答