将表单的数据提交到 java Set
是否可以在Struts2的action中将表单的数据提交给java Set?
Is it possible to submit a form's data to a java Set in an action of Struts2?
动作代码:
class TestAction extends ActionSupport{
private Set<Integer> mySet = new LinkedHashSet<Integer>();
public TestAction(){
}
public String test(){
someMethod(mySet);
}
... Getters/Setters ...
}
表格代码:
<form action="test.action" >
<input name="mySet[0]" />
<input name="mySet[1]" />
<input name="mySet[2]" />
<submit />
</form>
推荐答案
Set
只是一个集合,Struts2 内部支持任何类型的集合.但是对于这种类型的集合,您不能在 OGNL 表达式中使用索引.试试
The Set
is just a collection, and Struts2 has support for any type of collections internally. But for this type of collection you can't use indexes in your OGNL expressions. Try
<form action="test.action" >
<input name="mySet" />
<input name="mySet" />
<input name="mySet" />
<s:submit />
</form>
相关文章