考试系统中有单选题和多选题,这些单选题和多选题均可以用数组或者List收集用户输入的答案
1)答卷页面
<s:form action="calScore" method="post">
<p>单选题</p>
<p>第一题:</p>
你最喜欢哪种水果:<br/>
<input type="radio" name="single[0]" value = "苹果">苹果<br>
<input type="radio" name="single[0]" value = "桔子" checked>桔子<br>
<input type="radio" name="single[0]" value = "芒果">芒果<br>
<input type="radio" name="single[0]" value = "香蕉">香蕉<br>
<br/>
<p>第二题:</p>
你最喜欢哪种颜色:<br/>
<input type="radio" name="single[1]" value = "红色" checked>红色<br>
<input type="radio" name="single[1]" value = "蓝色" >蓝色<br>
<input type="radio" name="single[1]" value = "绿色">绿色<br>
<input type="radio" name="single[1]" value = "紫色">紫色<br>
<p>多选题:</p>
<p>第一题:</p>
你的兴趣爱好:<br/>
<input type="checkbox" name="mult[0].answerArr" value="看书"/>看书
<input type="checkbox" name="mult[0].answerArr" value="写代码"/>写代码
<input type="checkbox" name="mult[0].answerArr" value="旅游"/>旅游
<input type="checkbox" name="mult[0].answerArr" value="爬山"/>爬山
<br/>
<p>第二题:</p>
你喜欢的体育运动:<br/>
<input type="checkbox" name="mult[1].answerArr" value="篮球"/>篮球
<input type="checkbox" name="mult[1].answerArr" value="足球"/>足球
<input type="checkbox" name="mult[1].answerArr" value="排球"/>排球
<input type="checkbox" name="mult[1].answerArr" value="乒乓球"/>乒乓球<br/>
<s:submit value="交卷"></s:submit>
</s:form>2)处理action
package edu.njcit.action.exam;
import java.util.ArrayList;
import java.util.List;
import com.opensymphony.xwork2.ActionSupport;
import edu.njcit.action.ActionSupportBase;
import edu.njcit.entity.Multiple;
public class ExamAction extends ActionSupportBase {
private static final long serialVersionUID = 1L;
List<String> single=new ArrayList<String>();
List<Multiple> mult=new ArrayList<Multiple>();
@Override
public String execute() throws Exception {
return ActionSupport.SUCCESS;
}
public String calScore() throws Exception {
//单选题得分计算 TODO
System.out.println(single);
//多选题得分计算 TODO
System.out.println(mult);
return ActionSupport.SUCCESS;
}
public List<Multiple> getMult() {
return mult;
}
public void setMult(List<Multiple> mult) {
this.mult = mult;
}
public List<String> getSingle() {
return single;
}
public void setSingle(List<String> single) {
this.single = single;
}
}
其中Multiple类型可为:
package edu.njcit.entity;
public class Multiple {
private String[] answerArr=new String[4];
public String[] getAnswerArr(){
return answerArr;
}
public void setAnswerArr(String[] answerArr){
this.answerArr=answerArr;
}
}

本文介绍了一种利用数组和List收集用户答案的在线考试系统,包括单选题和多选题的实现方式。详细阐述了答卷页面设计和后端处理逻辑,以及如何计算单选题和多选题的得分。
3529

被折叠的 条评论
为什么被折叠?



