?? getscore.jsp
字號:
<%@page contentType="text/html;charset=GBK"%>
<%@page import="java.sql.*"%>
<jsp:useBean id="conn" scope="page" class="test.ConnOracle"/>
<%@ include file="/public/checkvalidstudent.jsp"%>
<%!
ResultSet rs = null; // 執行Sql語句返回的結果集
String sql = "";
String paperid = "";
String student_answer[] = new String[100];
String paper_answer[] = new String[100];
int correct_question = 0; // 記錄共答對了多少道題
int score = 0; // 總分
int tmp_paper_id;
int tmp_questionid;
int tmp_selectid;
%>
<%
// session paperid的值在exam2.jsp中設置
paperid = (String) session.getAttribute("paperid");
if(paperid == null) {
out.println("讀取試卷信息錯誤!");
return;
}
sql = "select paper_id,questionid,selectid,classid,classname,qname,choice1,choice2,choice3,choice4,answer from test_paper_info where paper_id=" + session.getAttribute("paperid");
rs = conn.executeQuery( sql );
int answer_index = 0;
String tmpbuffer[] = new String[4]; // 為了處理多選題,而使用的一個字符串數組
correct_question=0;
while(rs.next()) {
// 對單選題的處理
tmp_paper_id = rs.getInt("paper_id");
tmp_questionid = rs.getInt("questionid");
tmp_selectid = rs.getInt("selectid");
student_answer[answer_index] = "";
if(tmp_selectid==1) { //單項選擇和多項選擇的問題真多,郁悶,getInt總是出現無效的描述符索引錯誤,待解決中。。。
student_answer[answer_index] = request.getParameter(""+ tmp_questionid );
}else { // 對多選題的處理
tmpbuffer = request.getParameterValues(""+ tmp_questionid );
if(tmpbuffer!=null) {
for(int i=0; i<tmpbuffer.length; i++) {
if(tmpbuffer[i] != null)
student_answer[answer_index] += tmpbuffer[i];
}
}
}
paper_answer[answer_index] = rs.getString(11);
if(student_answer[answer_index]!=null && student_answer[answer_index].equals(paper_answer[answer_index]))
correct_question++;
answer_index++;
}
score = (int) (correct_question * 100 / answer_index);
// 下面將學生考試結果保存到test_result表中
sql = "insert into test_result (studentid,score,starttime,classid) values (";
sql+= (String)(session.getAttribute("studentid")) ;
// 下面用到的classid在頁面exam2.jsp中賦值
sql+= "," + score + ",getdate(),'" + (String)(session.getAttribute("classid")) + "')";
conn.executeUpdate( sql );
%>
<html>
<head>
<title>入學測試得分</title>
<link rel="stylesheet" href="../public/style.css">
</head>
<body bgcolor="#FFFFFF" background="../images/bg3.gif">
<center>
<br><br><br><br><br><br><br><br><br>
<table class=dbt2 width=640 cellSpacing=1 cellPadding=3 border=0>
<tr class=dbt3>
<td colspan=2 align="center">入學測試得分</td>
</tr>
<tr class=dbt4>
<td width="18%">id號:</td>
<td width="82%" align="center">
<%
if(session.getAttribute("studentid") != null)
out.println(session.getAttribute("studentid"));
%>
</td>
</tr>
<tr class=dbt4>
<td width="18%">姓名:</td>
<td width="82%" align="center">
<%
if(session.getAttribute("studentname") != null)
out.println(session.getAttribute("studentname"));
%>
</td>
</tr>
<tr class=dbt4>
<td width="18%">考試用時:</td>
<td width="82%" align="center">
<%
if(request.getParameter("totaltime")!=null)
out.println(request.getParameter("totaltime"));
%>分鐘</td>
</tr>
<tr class=dbt4>
<td width="18%">考試成績:</td>
<td width="82%" align="center">答對<%=correct_question%>道題,分數為<%=score%>分</td>
</tr>
<tr class=dbt4>
<td align="center" colspan="2"> 謝謝你參加此次考試!</td>
</tr>
<tr class=dbt4>
<td align="center" colspan="2">【<a href="javascript:window.close()">關閉窗口</a>】</td>
</tr>
</table>
</center>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -