getscore.jsp
资源名称:examasp.rar [点击查看]
上传用户:hjt198082
上传日期:2015-04-16
资源大小:95k
文件大小:4k
源码类别:
MySQL数据库
开发平台:
Java
- <%@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>