如何在Struts 2中映射select标签中的多个值?

我的Struts2 Web应用程序中有一个多选组合。 我使用ui-multisection组件。 当我选择并提交值"1""2"然后在我的动作类中检查它时,只设置了最后选择的值。 如何设置所有选定的值?

JSP文件:

  <link rel="stylesheet" href="" type="text/css" /> <link rel="stylesheet" href="" type="text/css" /> <link rel="stylesheet" href="" type="text/css" /> <script type="text/javascript" src=""> <script type="text/javascript" src=""> <script type="text/javascript" src=""> <script type="text/javascript" src="">  $(function() { $("select").multiselect({ multiple : true, selectedList : 4, noneSelectedText : 'Tous', height : 180 }); $("select").multiselect().multiselectfilter(); });   

动作类:

 package com.omb.controller.report; import java.util.ArrayList; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import com.omb.ui.item.Item; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.Preparable; @SuppressWarnings("serial") public class MyAction extends ActionSupport implements Preparable { Log log = LogFactory.getLog(MyAction.class); private List listItems = new ArrayList(); private List listIdSelected = new ArrayList(); public void prepare() throws Exception { listItems.add(new Item("1", "Item 1")); listItems.add(new Item("2", "Item 2")); listItems.add(new Item("3", "Item 3")); listItems.add(new Item("4", "Item 4")); } @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, readOnly = true) public String testOMB() throws Exception { log.debug("listIdSelected = " + listIdSelected.size()); return SUCCES; } public List getListItems() { return this.listItems; } public void setListItems(List listItems) { this.listItems = listItems; } public List getListIdSelected() { return this.listIdSelected; } public void setListIdSelected(List listIdSelected) { this.listIdSelected = listIdSelected; } } 

struts.xml文件:

 ?xml version="1.0" encoding="UTF-8" ?>                                11204928              errorAction   sessionInvalid  blank       errorTile   resultCache inputCache   login changePassword   welcome  /report perimetersReport      succesTile    

我该怎么办才能获得所有价值?

您应该select一个标签以接受多个选项。 这是通过struts select标签中的multiple="true"完成的。 然后你的拦截器堆栈是不完整的,因为缺少multiselect拦截器 。 您应该在fileupload拦截器引用之后将到拦截器堆栈。

尝试改变

 private List listIdSelected = new ArrayList(); 

 private List listIdSelected = new ArrayList(); 

因为你的Getters和Setter就是这样。