exam2.jsp
上传用户:hjt198082
上传日期:2015-04-16
资源大小:95k
文件大小:7k
源码类别:

MySQL数据库

开发平台:

Java

  1. <%@page contentType="text/html;charset=GBK"%>
  2. <%@page import="java.sql.*"%>
  3. <jsp:useBean id="conn" scope="page" class="test.ConnOracle"/>
  4. <%@ include file="/public/checkvalidstudent.jsp"%>
  5. <%!
  6.     ResultSet rs     = null;                 // 执行Sql语句返回的结果集
  7. String sql = "";
  8. String classid = "";
  9. String classname = "";                   // 测试班级名称
  10. int examtime = 0;              // 考试时间
  11. int total_question_in_paper;   // 每份试卷中的考题数目
  12. int total_paper_num=0;         // 试卷总数
  13. int paper_array[];
  14.     int curr_paperid=0;            // 当前命中的试卷号
  15. %>
  16. <%
  17. classid = request.getParameter("classid");
  18. if(classid == null) {
  19.     out.println("系统错误, 无正确的班级ID号!");
  20. return;
  21. }
  22. sql = "select * from test_classinfo where classid='" + classid + "'";
  23. try {
  24.     rs  = conn.executeQuery( sql );
  25. }catch(Exception ee) {
  26.     out.println("<center>");
  27. out.println("访问课程信息出错!请将以下信息告知系统管理员。<br>");
  28. out.println(ee.toString() + "<br>");
  29. out.println("<a href=javascript:history.back()>单击这里返回</a>");
  30.     out.println("</center>");
  31. }
  32. if(!rs.next()) {
  33.     out.println("数据库中没有课程信息,无法进行考试!");
  34.     return;
  35. }
  36. classname = rs.getString("classname");
  37. examtime  = rs.getInt("totaltime");
  38. total_question_in_paper = rs.getInt("totalques");
  39. total_paper_num = rs.getInt("totalpaper");
  40. // 下面从班级代码为classid的试卷中随机抽取一套,进行考试
  41. sql = "select distinct paper_id from test_paper_info where classid='" + classid + "'";
  42. rs  = conn.executeQuery( sql );
  43. if(!rs.next()) {
  44.        out.println("还没有班级代号为 " +  classid + " 的试题,请联系管理员!");
  45.    return;
  46. }
  47. paper_array = new int[total_paper_num];
  48. int index=0;
  49. do{
  50.     paper_array[index++] = rs.getInt("paper_id");
  51. }while(rs.next());
  52. curr_paperid = paper_array[(int)Math.floor(Math.random()*total_paper_num)];
  53. session.setAttribute("paperid",""+curr_paperid);
  54. session.setAttribute("classid",""+classid);
  55. sql = "select * from TEST_PAPER_INFO where paper_id=" + curr_paperid;
  56. rs  = conn.executeQuery( sql );
  57. %>
  58. <html>
  59. <head>
  60. <script language="JavaScript">
  61.  var hours
  62.  hours=0
  63.  var minutes
  64.  minutes=0
  65.  var seconds
  66.  seconds=1
  67.  function show1(){
  68.  var Digital=new Date()
  69.  var shours=Digital.getHours()
  70.  var sminutes=Digital.getMinutes()
  71.  var sseconds=Digital.getSeconds()
  72.  var dn="AM" 
  73.  if (shours>12){
  74.   dn="PM"
  75.   shours=shours-12
  76.  }
  77.  if (shours==0)
  78.   shours=12
  79.  if (sminutes<=9)
  80.   sminutes="0"+sminutes
  81.  if (sseconds<=9)
  82.   sseconds="0"+sseconds
  83.  var sctime="<b><font face='Verdana' color='#8000FF'>"+shours+":"+sminutes+":"+sseconds+" "+dn+"</font></b>"
  84.  if (!document.all)
  85.   document.write(sctime)
  86.  else
  87.   tick1.innerHTML=sctime
  88.  }
  89.  
  90.  function show2(){
  91.  seconds=parseInt(seconds)+1
  92.  minutes=parseInt(minutes)+0
  93.  hours=parseInt(hours)+0
  94.  
  95.  if (parseInt(seconds)==60){
  96.   minutes=parseInt(minutes)+1
  97.   seconds=0
  98.   }
  99.  if (parseInt(minutes)==<%=examtime%>){
  100.   alert("考试时间到!")
  101.   document.form1.submit()
  102.   return;
  103.   }
  104.   if (parseInt(minutes)==60){
  105.   hours=parseInt(hours)+1
  106.   minutes=0
  107.   }
  108.  if (minutes<=9){ 
  109.   if (seconds<=9){
  110.   var ctime="<b><font face='Verdana' color='#8000FF'>0"+hours+":0"+minutes+":0"+seconds+"</font></b>"
  111.   }else{
  112.   var ctime="<b><font face='Verdana' color='#8000FF'>0"+hours+":0"+minutes+":"+seconds+"</font></b>"
  113.   }
  114.  }else{
  115.   if (seconds<=9){
  116.   var ctime="<b><font face='Verdana' color='#8000FF'>0"+hours+":"+minutes+":0"+seconds+"</font></b>"
  117.   }else{
  118.   var ctime="<b><font face='Verdana' color='#8000FF'>0"+hours+":"+minutes+":"+seconds+"</font></b>"
  119.   }
  120.  }
  121.  
  122.  if (!document.all)
  123.  document.write(ctime)
  124.  else
  125.   tick2.innerHTML=ctime
  126.  }
  127.  
  128.  function loadclock(){
  129.  if (document.all)
  130.   show1()
  131.   setInterval("show2()",1000)
  132.  }
  133.  if (!document.all)
  134.   show2()
  135.  </script>
  136.  <Script Language=javascript >
  137.      function Click(){
  138.      if(event.button==2){alert
  139.      ('您不需要使用右键!');
  140.      }}
  141.      document.onmousedown=Click;
  142.      </Script>
  143. <title>入学测试试题</title>
  144. <link rel="stylesheet" href="../public/style.css">
  145. </head>
  146. <body bgcolor="#FFFFFF" onload="Javascript:loadclock()" background="../images/bg3.gif">
  147. <center>
  148.   <table width="756" border="0">
  149.     <tr> 
  150.       <td rowspan="2" valign="bottom"><b><font size="4" color="#FF0000"><%=classname%>入学测试</font></b> 
  151.        
  152.       </td>
  153.       <td width="125"> 
  154.         <div align="left"><b>考试时间</b>:<br>
  155.           <b><font face="Verdana" color="#8000FF" size="2"><%=examtime%> </font></b><font face="Verdana" color="#8000FF"><b>minutes</b></font></div>
  156.       </td>
  157.       <td width="125"> <b>开始时间</b>:<br>
  158.         <span id=tick1></span> </td>
  159.       <td width="125"> <b>使用时间:</b><br>
  160.         <span id=tick2></span> </td>
  161.     </tr>
  162.   </table>
  163. <hr size="1">
  164. <form name="form1" method="post" action="getscore.jsp" target="_top">
  165. <table width="400" border="0" align="center">
  166.   <tr>
  167.     <td><%=classname%>入学测试</td>
  168.   </tr>
  169. </table>
  170. <%
  171. int question_index=1;
  172. int tmp_questionid=0;
  173. while(rs.next()) {
  174. tmp_questionid=rs.getInt("QUESTIONID");
  175. %>
  176. <table width="75%" border="0">
  177.     <%
  178. if(rs.getInt("selectid")==1) {
  179.     %>
  180. <tr> 
  181.       <td width="15%" align="left" valign="top">答案</td>
  182.       <td width="85%"><%="<font color=blue>(" + question_index + ")</font> " + rs.getString("qname")%>(单选题)</td>
  183.     </tr>
  184. <tr>
  185.           <td> <input type="radio" name="<%=tmp_questionid%>" value="A">A</td><td><%=rs.getString("choice1")%></td></tr>
  186.   <tr>
  187.           <td> <input type="radio" name="<%=tmp_questionid%>" value="B">B</td><td><%=rs.getString("choice2")%></td></tr>
  188. <tr>
  189.           <td> <input type="radio" name="<%=tmp_questionid%>" value="C">C</td><td><%=rs.getString("choice3")%></td></tr>
  190. <tr>
  191.           <td> <input type="radio" name="<%=tmp_questionid%>" value="D">D</td><td><%=rs.getString("choice4")%></td></tr>
  192.     <%
  193.     }else {
  194. %>
  195. <tr> 
  196.       <td width="15%" align="left" valign="top">答案</td>
  197.       <td width="85%"><%="<font color=blue>(" + question_index + ")</font> " + rs.getString("qname")%><font color=red>(多选题)</font></td>
  198.     </tr>
  199. <tr>
  200.           <td> <input type="checkbox" name="<%=tmp_questionid%>" value="A">A</td><td><%=rs.getString("choice1")%></td></tr>
  201.   <tr>
  202.           <td> <input type="checkbox" name="<%=tmp_questionid%>" value="B">B</td><td><%=rs.getString("choice2")%></td></tr>
  203. <tr>
  204.           <td> <input type="checkbox" name="<%=tmp_questionid%>" value="C">C</td><td><%=rs.getString("choice3")%></td></tr>
  205. <tr>
  206.           <td> <input type="checkbox" name="<%=tmp_questionid%>" value="D">D</td><td><%=rs.getString("choice4")%></td></tr>
  207.     <%}%>
  208.     </table><p></p>
  209. <%
  210. question_index++;
  211. }  
  212. %>
  213. <p align="center"> 
  214.     <input type="hidden" name="totaltime" value="0">
  215.     <input type="button" name="submita" value="提交答卷"  onclick="JavaScript:subit()">
  216.   </p>
  217. </form>
  218. </center>
  219. </body>
  220. </html>
  221. <script language="JavaScript">
  222. function subit(){
  223. if ((confirm("你确定提交试卷吗?n点“确定”提交,点“取消”返回检查"))==true){
  224. document.form1.totaltime.value = minutes;
  225. document.form1.submit();
  226. }
  227. }
  228. </script>