如何检索struts2复选框列表值
我将创建一个带有复选框列表的列表。对于那些我使用以下代码的用户:如何检索struts2复选框列表值,struts2,checkboxlist,Struts2,Checkboxlist,我将创建一个带有复选框列表的列表。对于那些我使用以下代码的用户: <s:form action="accept" namespace="/manager/course"> <s:checkboxlist list="courseRequests" name="acceptList" listValue="studentNickname" listKey="studentId" theme="checkbox-fix"/> <s:url act
<s:form action="accept" namespace="/manager/course">
<s:checkboxlist list="courseRequests" name="acceptList" listValue="studentNickname" listKey="studentId" theme="checkbox-fix"/>
<s:url action="accept" namespace="/manager/course" var="accList" />
<s:a href="%{accList}"><s:text name="Accept"/> </s:a>
</s:form>
private int[] acceptList;
public void setAcceptList(int[] acceptList){
this.acceptList=acceptList;
}
还有其他一些代码,但我所有的状态都是null
。
我是否使用了错误的代码?在标记中,请执行以下操作:
<input type="checkbox" name="thename" id="checkbox_id1" value="value1" />
<input type="checkbox" name="thename" id="checkbox_id2" value="value2" />
在代码中检索它之前,您需要发送它。@AleksandrM opes。我想我的脑子被绞死了:D.我被试过了,却忘了。
<input type="checkbox" name="thename" id="checkbox_id1" value="value1" />
<input type="checkbox" name="thename" id="checkbox_id2" value="value2" />
// action/object code...
Set<String> cbox = new HashSet();
public void setThename(String[] thenames) {
for (String thename : thenames) {
cbox.add(thename);
}
}
// action/object code...
if (cbox != null) {
for (String s : cbox) {
log.info(s);
}
}