实现单多选都可以选,以及如何获得提交的答案。
代码如下:
jsp代码:
<s:form action="fx" method="post">
<s:iterator value="#request.xuanze3" var="xuanze3" status="stat" id="xuanze3">
<s:if test="ddx==0">
<table>
<tr>
<td width="640" height="36">
<font color="blue">
<s:property value="#stat.index+1" /> .
<s:property value="tg" />
<s:hidden name="da1" value="%{da}"/>
<s:hidden name="zsdbh1" value="%{zsd.id.zsdbh}"/>
</font>
</td>
</tr>
<tr>
<td height="36" width="640" align="left">
<s:radio list='#{"A":"A、"+xx1, "B":"B、"+xx2, "C":"C、"+xx3,"D":"D、"+xx4}'
name="answer[%{#stat.index}]" value="" theme="simple"/>
</td>
</tr>
</table>
</s:if>
<s:else>
<table>
<tr>
<td width="640" height="36">
<font color="blue">
<s:property value="#stat.index+1" /> .
<s:property value="tg" />
<s:hidden name="da1" value="%{da}"/>
<s:hidden name="zsdbh1" value="%{zsd.id.zsdbh}"/>
</font>
</td>
</tr>
<tr>
<td height="36" width="640" align="left">
<s:checkboxlist list='#{"A":"A、"+xx1, "B":"B、"+xx2, "C":"C、"+xx3,"D":"D、"+xx4}'
name="answer[%{#stat.index}]" theme="simple"/>
</td>
</tr>
</table>
</s:else>
<hr/>
</s:iterator>
<tr>
<td><s:submit value="submit" name="submit" /></td>
</tr>
</s:form>
其中的hidden标签是用来向后台返回数据的,不需要的话可以不用。
action层定义private List<List> answer=new ArrayList<List>();//用于接收前台传来的测试者的答案。
要有get、set方法
这样,就可以获得每道题选中的项了!!