在做在线考试系统中,请教一下自动改卷的问题?
我做了一个虚拟的表用来存放用户考试的结果,如果有50道题,则form里面有answer1......answer50,随机抽题的时候是用的<c:foreach>所以<input name="answeri">但是i的值不知道怎么放?而却比较的时候从数据库中取的值${kaoti.answer}要怎么和answeri比较??到底要怎 么样比较啊??
请高手帮我指点指点。。
我做了一个虚拟的表用来存放用户考试的结果,如果有50道题,则form里面有answer1......answer50,随机抽题的时候是用的<c:foreach>所以<input name="answeri">但是i的值不知道怎么放?而却比较的时候从数据库中取的值${kaoti.answer}要怎么和answeri比较??到底要怎 么样比较啊??
请高手帮我指点指点。。
<c:forEach items='${(request.setAttribute()中的字段名)}' var='kaoti'>
<input name='answer${x}' type='text'/>
<input name='answer_${x}' value='${kaoti.answer}' type='hidden'/>
<c:set var='x' value='${x+1}'>
</c:forEach>
<input value='提交' type='button' onclick='eq(${x});'>
<script>
function eq(max)
{
for(var i=0;i<max;i++)
{
if(document.getElementById('answer'+i).value==document.getElementById('answer_'+i).value)
{
alert("第"+(i+1)+"道题正确");
}
else
{
alert(("第"+(i+1)+"道题错误");
}
}
}
</script>
思路大概是这样,细节可改变的地方很多,这只是其中一种方法
<c:set var='x' value='0'>
<c:forEach items='${(request.setAttribute()中的字段名)}' var='kaoti'>
<input name='answer${x}' type='text'/>
<input name='answer_${x}' value='${kaoti.answer}' type='hidden'/>
<c:set var='x' value='${x+1}'>
</c:forEach>
<input value='提交' type='button' onclick='eq(${x});'>
<input name='answer_new' type='hidden' value=''/>
<input name='answer_old' type='hidden' value=''/>
</form>
<script>
function eq(max)
{
var str1="";
var str2="";
for(var i=0;i <max;i++)
{
if(i==0)
{
str1=document.getElementById('answer'+i).value;
str2=document.getElementById('answer_'+i).value;
}
else
{
str1=str1+","+document.getElementById('answer'+i).value;
str2=str2+","+document.getElementById('answer_'+i).value;
}
}
document.form1.submit();
}
</script>
action:
String [] arr1=answer_old.split(",");
String [] arr2=answer_new.split(",");
for(int i=0;i<arr1.length;i++)
{
if(arr1[i].equals(arr2[i]))
{
System.out.println("第"+(i+1)+"道题正确");
}
else
{
System.out.println("第"+(i+1)+"道题错误");
}
}
还有我不需要弹出式的,我需要的在另外一个页面统计出对错的个数
String [] arr1=answer_old.split(",");
String [] arr2=answer_new.split(",");
int right=0;
int error=0;
for(int i=0;i <arr1.length;i++)
{
if(arr1[i].equals(arr2[i]))
{
right++;
}
else
{
error++;
}
}
request.setAttribute("right",right);
request.setAttribute("error",error);跳转页面用<%=request.getAttribute("right")%>和<%=request.getAttribute("error")%>取出
下划线的地方是什么意思啊