UnitTestPaper.jsp
上传用户:nbluoke
上传日期:2013-08-09
资源大小:4851k
文件大小:5k
源码类别:

教育系统应用

开发平台:

WORD

  1. <%@ page contentType="text/html; charset=gb2312" language="java" %>
  2. <%@ page import="java.sql.*" %>
  3. <%@ page import="jinghua.*"%>
  4. <%@ page import="java.text.*" %>
  5. <jsp:useBean id="DBCon" class="jinghua.JinghuaConn" scope="session">
  6. </jsp:useBean>
  7. <%! boolean debug=false;%>
  8. <%
  9. String testID=request.getParameter("testID");
  10. String studentID=request.getParameter("stuID");
  11. //http://localhost:8080/jinghua/student/UnitTestPaper.jsp?testID=100&stuID=s11
  12. //String testID="100";
  13. //String studentID="s11";
  14. ResultSet rs=null;
  15. String sql="";
  16. String title="";
  17. int testnum=0;
  18. int testmark=0;
  19. PreparedStatement pstmt=null;
  20. StringBuffer dbmsg=new StringBuffer();
  21. StringBuffer testIDs=new StringBuffer();
  22. //StringBuffer Answer=new StringBuffer();
  23. //StringBuffer Mark=new StringBuffer();
  24. int testNumber=0;
  25. try{
  26.     Connection con=DBCon.getConnection();
  27.     sql="select id,paper,title,testnum from test where id="+testID;
  28.     pstmt=con.prepareStatement(sql);
  29.     rs=pstmt.executeQuery();
  30.     if(rs.next()){
  31.         //分析试题:试题ID@答案@分数@难易度;     一道试题的格式,以#号结束
  32.         String paper=rs.getString("paper");
  33.         title=rs.getString("title");
  34.         testnum=rs.getInt("testnum");
  35.         if(debug) dbmsg.append("<br>paper="+paper);
  36.         String [] tests=paper.split("#");
  37.         for(int i=0;i<tests.length;i++){
  38.             //取回试题号
  39.             String [] test=tests[i].split("@");
  40.             testIDs.append(test[0]+",");//题号
  41.             //Answer.append(test[1]+"#");//答案
  42. //Mark.append(test[2]+"#");
  43.             testmark+=Float.parseFloat(test[2]);
  44.         }
  45.         sql=testIDs.toString().substring(0,testIDs.length()-1);
  46.         sql="select id,questtext,mark from question where id in ("+sql+") order by id";
  47. rs.close();
  48.         pstmt.close();
  49.         pstmt=con.prepareStatement(sql);
  50.         rs=pstmt.executeQuery();
  51. %>
  52. <html>
  53. <head>
  54. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  55. <title>考试阶段 | <%=title%> | 单项选择题</title>
  56. <link rel="stylesheet" type="text/css" href="../css.css">
  57. </head>
  58. <body>
  59. <center>
  60.   <table border="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2" height="71">
  61.     <tr>
  62.       <td width="100%" height="29" style="border-left-style: solid; border-left-width: 0; border-right-style: solid; border-right-width: 0; border-top-style: solid; border-top-width: 0; border-bottom: 1px solid #000000">
  63.         <img src="../images/ksks.gif" width="108" height="28" border="0"></td>
  64.     </tr>
  65.     <tr>
  66.       <td height="21">当前位置:考试阶段 &gt; </td>
  67.     </tr>
  68.     <tr>
  69.         <TD class=p2 height=30><center>
  70.                     <font color="#74a8d1" size="+2">
  71.                             <strong><B>
  72.                                 <%=title%>
  73.                                     </B>
  74.                             </strong>
  75.                         </font></center></TD>
  76.     </tr>
  77.   </table>
  78. </center>
  79. <center><form name="viewdatabase"  ACTION="unit_sel_rs.jsp"  method="post">
  80.   <table border="1" cellspacing="1" style="border-collapse: collapse" bordercolor="#799AE1" width="100%" id="AutoNumber1" height="82">
  81.     <tr class="trh">
  82.       <td width="44" align="center" bgcolor="#799AE1" height="24">
  83.       <font color="#FFFFFF"><b>序号</b></font></td>
  84.       <td align="center" bgcolor="#799AE1" width="592" height="24">
  85.       <p align="center"><font color="#FFFFFF"><b>单项选择题(共<%=testnum%>题,<%=testmark%>分)</b></font></td>
  86.     </tr>
  87.     <%while(rs.next()){%>
  88.     <tr class="trh1">
  89.         <td align="center"   height="35" width="44"> 
  90.           <table width="100%" border="0">
  91.             <tr>
  92.               <td><center><%=(++testNumber)%></center></td>
  93.             </tr>
  94.             <tr>
  95.               <td><center><%DecimalFormat df=new DecimalFormat("###");
  96.                   String numNF=df.format(rs.getFloat("mark"));
  97.               out.print("("+numNF+")分");%></center></td>
  98.             </tr>
  99.           </table></td>
  100.       <td align="left" width="592" height="35">
  101.        <br>
  102.         <%=rs.getString("questtext")%>
  103.         <br>
  104.        </td>
  105.     </tr>
  106.     <%}
  107.     rs.close();
  108.     pstmt.close();
  109.     %>
  110.     <tr>
  111.         <td align="center" bgcolor="#FFFFFF" height="16" width="640" colspan="2" bordercolor="#FFFFFF">
  112.           <input class="s02"  type="submit" value="提交" name="submit1">
  113.           &nbsp;&nbsp;
  114.           <input class="s02" type="reset" name="submit2" value="重置">
  115.           <input name="testid" type="hidden" id="testid2" value="<%=testID %>">
  116.           <input name="studentid" type="hidden" id="studentid2" value="<%=studentID %>">
  117.         </td>
  118.       </tr>
  119.   </table>
  120. </form>
  121.  </center>
  122. </body>
  123. </html>
  124. <%
  125. }else{
  126.         Tools.showalert("从数据库中取出试题出错,没有找到相应试卷!",out);
  127.         Tools.goback(out);
  128. }
  129. }catch(SQLException e){
  130.     out.print("<br>SQL Error:sql="+sql+"<br>"+e.toString());
  131. }catch(Exception e){
  132.     out.print(e.toString() );
  133. }
  134. finally{
  135.     DBCon.dropConnection();
  136. }
  137. %>