是否可以在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>
这篇关于将表单的数据提交到 java Set的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!