<div class="select_wrap">
<select name="sampleselect" class="select_field" multiple="multiple" >
<option>Select Id </option>
<s:iterator value="userList" var="usrList" status="s">
<option value=<s:property value="#usrList"></s:property>><s:property value="#usrList"></s:property></option>
</s:iterator>
</select>
</div>
<br /><br />
<s:submit value="Compliance Export" name="Export Data" align="left" action="exportExcelAction4"/>
usrList正在从数据库中填充
在我的动作课上
private List<String> sampleselect=new ArrayList<String>();
public List<String> getSampleselect() {
return sampleselect;
}
public void setSampleselect(List<String> sampleselect) {
this.sampleselect = sampleselect;
}
但是这个样本选择没有填充.
最佳答案 list属性用于获取可迭代源,而name属性用于设置所选项.还可以使用< s:select />标记为更干净(更容易)的代码.例如:
在struts.xml
<action name="firstAction" class="foo.bar.FirstAction">
<result>firstPage.jsp</result>
</action>
<action name="secondAction" class="foo.bar.SecondAction">
<result>secondPage.jsp</result>
</action>
FirstAction.java
private List<String> userList;
/* Getter and Setter */
public String execute(){
// Load your data from database
userList = getMyService().findUserList();
return SUCCESS;
}
FirstPage.jsp
<s:form action="secondAction" >
<div class="select_wrap">
<s:select list = "userList"
name = "selectedItem"
cssClass = "select_field"
multiple = "multiple" />
</div>
<s:submit value="Post your selection to second Action" />
</s:form>
SecondAction.java
private String selectedItem;
/* Getter and Setter */
public String execute(){
log.debug("Selected item is: " + selectedItem);
return SUCCESS;
}
SecondPage.jsp
<div>
Selected item is: <s:property value="selectedItem" />
</div>