Submitting form's data to a java Set

ε祈祈猫儿з 提交于 2019-12-18 07:09:29

问题


Is it possible to submit a form's data to a java Set in an action of Struts2?

Action code:

class TestAction extends ActionSupport{

 private Set<Integer> mySet = new LinkedHashSet<Integer>();

 public TestAction(){
 }

 public String test(){

  someMethod(mySet);

 }

  ... Getters/Setters ...

}

Form code:

<form action="test.action" >
 <input name="mySet[0]" />
 <input name="mySet[1]" />
 <input name="mySet[2]" />
 <submit />
</form>

回答1:


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>


来源:https://stackoverflow.com/questions/24440274/submitting-forms-data-to-a-java-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!