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

教育系统应用

开发平台:

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. <%@ page import="java.util.*" %>
  6. <jsp:useBean id="DBCon" class="jinghua.JinghuaConn" scope="session">
  7. </jsp:useBean>
  8. <%! boolean debug=false;
  9. String studentID;
  10. %>
  11. <%
  12. try{
  13.     studentID=(String)session.getAttribute("studentID");
  14.     //Tools.showalert(studentID,out);
  15.     if(studentID==null){
  16.         throw new Exception();
  17.     }
  18. }catch(Exception e){
  19.     Tools.showalert("您还没有登录,或连接超时,请重新登录!",out);
  20.     Tools.showJS("window.open('../login.jsp','_self')",out);
  21. }
  22. int subID=Integer.parseInt(request.getParameter("Subject"));//-1为全部
  23. int knowID=Integer.parseInt(request.getParameter("KnowPoint"));//-1为全部
  24. //1:任意;2:容易;3:中等;4:较难
  25. int hardID=Integer.parseInt(request.getParameter("hard"));
  26. //testorder:2随机顺序;2从难到易;3从易到难
  27. int testorder=Integer.parseInt(request.getParameter("testorder"));
  28. int testnumber=Integer.parseInt(request.getParameter("testnumber"));
  29. //难易度设置:A,B,C,D,E
  30. //容易:E:30%,D:30%,C:30%;B:10%
  31. //中等:D:20%,C:30%,B:30%,A:10%,E:10%;
  32. //较难:C:20%,B:20%,A:50%,D:10%
  33. int numA=0,numB=0,numC=0,numD=0,numE=0,numElse=0;//各难度试题的个数
  34. switch(hardID){
  35.     case 1:
  36.         numElse=testnumber;
  37.         break;
  38.     case 2:
  39.         numA=0;
  40.         numB=(int)Math.floor(testnumber*0.1);
  41.         numC=(int)Math.floor(testnumber*0.3);
  42.         numD=(int)Math.floor(testnumber*0.3);
  43.         numE=(int)Math.floor(testnumber*0.3);
  44.         numElse=testnumber-numA-numB-numC-numD-numE;
  45.         break;
  46.     case 3:
  47.         numA=(int)Math.floor(testnumber*0.1);
  48.         numB=(int)Math.floor(testnumber*0.3);
  49.         numC=(int)Math.floor(testnumber*0.3);
  50.         numD=(int)Math.floor(testnumber*0.2);
  51.         numE=(int)Math.floor(testnumber*0.1);
  52.         numElse=testnumber-numA-numB-numC-numD-numE;
  53.         break;
  54.     case 4:
  55.         numA=(int)Math.floor(testnumber*0.4);
  56.         numB=(int)Math.floor(testnumber*0.2);
  57.         numC=(int)Math.floor(testnumber*0.2);
  58.         numD=(int)Math.floor(testnumber*0.1);
  59.         numE=(int)Math.floor(testnumber*0.1);
  60.         numElse=testnumber-numA-numB-numC-numD-numE;
  61.         break;
  62. }
  63. if(debug){
  64.     out.print("<br>studentID="+studentID+
  65.             "<br>subID="+subID+
  66.             "<br>knowID="+knowID+
  67.             "<br>hardID="+hardID+
  68.             "<br>testorder="+testorder+
  69.             "<br>numA="+numA+
  70.             "<br>numB="+numB+
  71.             "<br>numC="+numC+
  72.             "<br>numD="+numD+
  73.             "<br>numE="+numE+
  74.             "<br>numElse="+numElse
  75.             );
  76. }
  77. ResultSet rs=null;
  78. String sql="";
  79. String sqlcon="";
  80. String sqlorder="";
  81. int testnum=0;
  82. int testmark=0;
  83. int i=0;
  84. String strQuestIDs=null;
  85. Statement stmt=null;
  86. StringBuffer testIDs=new StringBuffer();
  87. //StringBuffer Answer=new StringBuffer();
  88. //StringBuffer Mark=new StringBuffer();
  89. int testNumber=0;
  90. try{
  91.     Connection con=DBCon.getConnection();
  92. //构造查询条件
  93. //科目
  94. sqlcon="(`question`.`Source` =1)";
  95. if(subID!=-1){
  96.     sqlcon=sqlcon+" AND "+" (`question`.`SubjectID`="+subID+") ";
  97. }
  98. //知识点
  99. if(knowID!=-1){
  100.     if(sqlcon.equals(""))
  101.         sqlcon=" ((`question`.`KnowPointID1` = "+knowID+") OR "+
  102.                 "  (`question`.`KnowPointID2` = "+knowID+") OR "+
  103.                 "  (`question`.`KnowPointID3` = "+knowID+")) ";
  104.     else
  105.         sqlcon=sqlcon+ " AND "+
  106.                 "((`question`.`KnowPointID1` = "+knowID+") OR "+
  107.                 "  (`question`.`KnowPointID2` = "+knowID+") OR "+
  108.                 "  (`question`.`KnowPointID3` = "+knowID+")) ";
  109. }
  110. if(debug){
  111.     out.println("<br>sqlcon="+sqlcon);
  112. }
  113. //testorder:2随机顺序;2从难到易;3从易到难
  114. switch(testorder){
  115.     case 1:
  116.         sqlorder=" ORDER BY RAND()";
  117.         break;
  118.     case 2:
  119.         sqlorder=" ORDER BY `question`.`PreHard` ASC,`question`.`ID` ASC";
  120.         break;
  121.     case 3:
  122.         sqlorder=" ORDER BY `question`.`PreHard` DESC,`question`.`ID` ASC";
  123.         break;
  124.     default:
  125.         break;
  126. }
  127. //难易度
  128. Vector questIDs=new Vector();
  129. //A
  130. if(numA>0){
  131.     if(sqlcon.equals(""))
  132.         sql="SELECT   `question`.`ID` FROM  `question` WHERE "+
  133.                 "(`question`.`PreHard` = 'A')"+" ORDER BY RAND() "+" LIMIT  "+numA;
  134.     else
  135.         sql="SELECT   `question`.`ID` FROM  `question` WHERE "+
  136.             sqlcon+" AND "+"(`question`.`PreHard` = 'A')"+" ORDER BY RAND() "+" LIMIT  "+numA;
  137.     try{
  138.         stmt=con.createStatement();
  139.         rs=stmt.executeQuery(sql);
  140.         while(rs.next()){
  141.             questIDs.addElement(new String(rs.getString("ID")));
  142.         }
  143.         if(debug)
  144.             out.print("<br>select numA sql="+sql);
  145.     }
  146.     catch(Exception e){
  147.         out.print("<br> query question hard A error sql="+sql);
  148.         out.print("<br>"+e.toString());
  149.     }
  150. }
  151. if(debug){
  152.     out.print("<br>vector number A="+questIDs.size());
  153. }
  154. //B
  155. if(numB>0){
  156.     if(sqlcon.equals(""))
  157.         sql="SELECT   `question`.`ID` FROM  `question` WHERE "+
  158.                 "(`question`.`PreHard` = 'B')"+" ORDER BY RAND() "+" LIMIT  "+numB;
  159.     else
  160.         sql="SELECT   `question`.`ID` FROM  `question` WHERE "+
  161.             sqlcon+" AND "+"(`question`.`PreHard` = 'B')"+" ORDER BY RAND() "+" LIMIT  "+numB;
  162.     try{
  163.         stmt=con.createStatement();
  164.         rs=stmt.executeQuery(sql);
  165.         while(rs.next()){
  166.             questIDs.addElement(new String(rs.getString("ID")));
  167.         }
  168.         if(debug)
  169.             out.print("<br>select numB sql="+sql);
  170.     }
  171.     catch(Exception e){
  172.         out.print("<br> query question hard B error sql="+sql);
  173.         out.print("<br>"+e.toString());
  174.     }
  175. }
  176. if(debug){
  177.     out.print("<br>vector number B="+questIDs.size());
  178. }
  179. //C
  180. if(numC>0){
  181.     if(sqlcon.equals(""))
  182.         sql="SELECT   `question`.`ID` FROM  `question` WHERE "+
  183.                 "(`question`.`PreHard` = 'C')"+" ORDER BY RAND() "+" LIMIT  "+numC;
  184.     else
  185.         sql="SELECT   `question`.`ID` FROM  `question` WHERE "+
  186.             sqlcon+" AND "+"(`question`.`PreHard` = 'C')"+" ORDER BY RAND() "+" LIMIT  "+numC;
  187.     try{
  188.         stmt=con.createStatement();
  189.         rs=stmt.executeQuery(sql);
  190.         while(rs.next()){
  191.             questIDs.addElement(new String(rs.getString("ID")));
  192.         }
  193.         if(debug)
  194.             out.print("<br>select numC sql="+sql);
  195.     }
  196.     catch(Exception e){
  197.         out.print("<br> query question hard C error sql="+sql);
  198.         out.print("<br>"+e.toString());
  199.     }
  200. }
  201. if(debug){
  202.     out.print("<br>vector number C="+questIDs.size());
  203. }
  204. //D
  205. if(numD>0){
  206.     if(sqlcon.equals(""))
  207.         sql="SELECT   `question`.`ID` FROM  `question` WHERE "+
  208.                 "(`question`.`PreHard` = 'D')"+" ORDER BY RAND() "+" LIMIT  "+numD;
  209.     else
  210.         sql="SELECT   `question`.`ID` FROM  `question` WHERE "+
  211.             sqlcon+" AND "+"(`question`.`PreHard` = 'D')"+" ORDER BY RAND() "+" LIMIT  "+numD;
  212.     try{
  213.         stmt=con.createStatement();
  214.         rs=stmt.executeQuery(sql);
  215.         while(rs.next()){
  216.             questIDs.addElement(new String(rs.getString("ID")));
  217.         }
  218.         if(debug)
  219.             out.print("<br>select numD sql="+sql);
  220.     }
  221.     catch(Exception e){
  222.         out.print("<br> query question hard D error sql="+sql);
  223.         out.print("<br>"+e.toString());
  224.     }
  225. }
  226. if(debug){
  227.     out.print("<br>vector number D="+questIDs.size());
  228. }
  229. //E
  230. if(numE>0){
  231.     if(sqlcon.equals(""))
  232.         sql="SELECT   `question`.`ID` FROM  `question` WHERE "+
  233.                 "(`question`.`PreHard` = 'E')"+" ORDER BY RAND() "+" LIMIT  "+numE;
  234.     else
  235.         sql="SELECT   `question`.`ID` FROM  `question` WHERE "+
  236.             sqlcon+" AND "+"(`question`.`PreHard` = 'E')"+" ORDER BY RAND() "+" LIMIT  "+numE;
  237.     try{
  238.         stmt=con.createStatement();
  239.         rs=stmt.executeQuery(sql);
  240.         while(rs.next()){
  241.             questIDs.addElement(new String(rs.getString("ID")));
  242.         }
  243.         if(debug)
  244.             out.print("<br>select numE sql="+sql);
  245.     }
  246.     catch(Exception e){
  247.         out.print("<br> query question hard E error sql="+sql);
  248.         out.print("<br>"+e.toString());
  249.     }
  250. }
  251. if(debug){
  252.     out.print("<br>vector number E="+questIDs.size());
  253. }
  254. //Else  strQuestIDs
  255. if(questIDs.size()<testnumber){
  256. //if(numElse>0){
  257.     numElse=testnumber-questIDs.size();
  258.     StringBuffer sb=new StringBuffer();
  259.     for(i=0;i<questIDs.size();i++)
  260.         sb.append(questIDs.elementAt(i)+",");
  261.     if(sb.length()>0){
  262.         strQuestIDs=sb.toString().substring(0,sb.toString().length()-1);
  263.     }
  264.     else
  265.         strQuestIDs="-1";
  266.     sb=null;
  267.     if(sqlcon.equals(""))
  268.         sql="SELECT   `question`.`ID` FROM  `question` WHERE "+
  269.                 "(`question`.`ID` NOT IN ("+strQuestIDs+"))"+" ORDER BY RAND() "+" LIMIT  "+numElse;
  270.     else
  271.         sql="SELECT   `question`.`ID` FROM  `question` WHERE "+
  272.             sqlcon+" AND "+"(`question`.`ID` NOT IN ("+strQuestIDs+"))"+" ORDER BY RAND() "+" LIMIT  "+numElse;
  273.     if(debug)
  274.         out.print("<br>query question numElse sql="+sql);
  275.     try{
  276.         stmt=con.createStatement();
  277.         rs=stmt.executeQuery(sql);
  278.         while(rs.next()){
  279.             questIDs.addElement(new String(rs.getString("ID")));
  280.         }
  281.     }
  282.     catch(Exception e){
  283.         out.print("<br> query question hard Else error sql="+sql);
  284.         out.print("<br>"+e.toString());
  285.     }
  286. }
  287. if(debug){
  288.     out.print("<br>vector number Else="+questIDs.size());
  289. }
  290. switch(testorder){
  291.     case 1:
  292.         sqlorder=" ORDER BY RAND()";
  293.         break;
  294.     case 2:
  295.         sqlorder=" ORDER BY `question`.`PreHard` ASC,`question`.`ID` ASC";
  296.         break;
  297.     case 3:
  298.         sqlorder=" ORDER BY `question`.`PreHard` DESC,`question`.`ID` ASC";
  299.         break;
  300.     default:
  301.         break;
  302. }
  303. StringBuffer sb=new StringBuffer();
  304. for(i=0;i<questIDs.size();i++)
  305.     sb.append(questIDs.elementAt(i)+",");
  306. if(sb.length()>0){
  307.     strQuestIDs=sb.toString().substring(0,sb.toString().length()-1);
  308. }
  309. else
  310.     strQuestIDs="-1";
  311. sb=null;
  312. if(debug)
  313.     out.print("<br>strQuestIDs="+strQuestIDs);
  314. sql="SELECT  `question`.`ID`,`question`.`PreHard` , `question`.`QuestText`,  "+
  315.     " `question`.`Mark`,  `question`.`Answer`"+
  316.     " FROM  `question` "+
  317.     " WHERE `question`.`ID` IN("+strQuestIDs+") "+sqlorder+" LIMIT "+testnumber;
  318.     if(debug)
  319.         out.print("<br>paper sql="+sql);
  320.     stmt=con.createStatement();
  321.     rs=stmt.executeQuery(sql);
  322.     testmark=0;
  323.     testnum=0;
  324.     while(rs.next()){
  325.         testmark+=rs.getInt("Mark");
  326.         testnum++;
  327.         //试题ID@答案@分数@难易度;     一道试题的格式,以#号结束
  328.         testIDs.append(rs.getString("ID")+"@"+rs.getString("Answer")+"@"+rs.getString("Mark")+
  329.             "@"+ rs.getString("PreHard")+"#");
  330.     }
  331.     rs.beforeFirst();
  332.     if(debug){
  333.         out.print("<br>query question sql="+sql);
  334.     }
  335. %>
  336. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  337. <!-- saved from url=(0041)http://jsptestonline.cosoft.org.cn/senior/none_xt.jsp -->
  338. <HTML><HEAD><TITLE>共创学堂-错题本在线测验</TITLE>
  339. <META http-equiv=Content-Type content="text/html; charset=gb2312">
  340. <LINK
  341. href="../student/style/style.css" type=text/css rel=stylesheet>
  342. <SCRIPT src="../student/js/html.js"></SCRIPT>
  343. <SCRIPT src="../student/js/gnb_menus_layer.js"></SCRIPT>
  344. <SCRIPT src="../student/js/menu.js"></SCRIPT>
  345. <SCRIPT src="../student/js/jumpmenu.js"></SCRIPT>
  346. <SCRIPT src="../student/js/Valid.js"></SCRIPT>
  347. <META content="MSHTML 6.00.2722.900" name=GENERATOR></HEAD>
  348. <BODY text=#000000 bgColor=#ffffff>
  349. <CENTER>
  350.   <form  ACTION="free_test_rs.jsp"  method="post" name="viewdatabase" target="_blank">
  351.     <table width="650" border="0" cellspacing="0" cellpadding="0">
  352.     <tr>
  353.       <td><img src="../student/images/test_pop_01.gif" width="102" height="27"></td>
  354.       <td align="right"><img src="../student/images/test_pop_02.gif" width="134" height="27"></td>
  355.     </tr>
  356.   </table>
  357.   <!--begin test -->
  358.   <table width="650" border="0" cellspacing="0" cellpadding="0">
  359.     <tr>
  360.       <td class="title1" align="center"><font color="#74a8d1" size="+2">
  361.                             <strong><B>
  362.                                 共创学堂-自由测验
  363.                                     </B>
  364.                             </strong>
  365.                         </font></td>
  366.     </tr>
  367.   </table>
  368.   <br>
  369.   <table id=AutoNumber1 style="BORDER-COLLAPSE: collapse"
  370. height=82 cellspacing=1 width="650" border=0 cellpadding="2" bgcolor="#c1c1c1">
  371.     <tbody>
  372.       <tr class=trh>
  373.         <td align=center width=80 bgcolor=#eaeaea><b>序号</b></td>
  374.         <td align=middle bgcolor=#eaeaea> <p align=center><b>共<%=testnum%>题,<%=testmark%>分</b></p></td>
  375.       </tr>
  376.   <%while(rs.next()){%>
  377.       <tr class=trh1 bgcolor="#FFFFFF">
  378.           <td width=80 align=center valign="middle"> 
  379.             <table width="100%" border=0>
  380.               <tbody>
  381.                 <tr align="center">
  382.                   <td colspan="2">
  383.                     <center>
  384.                       <%=(++testNumber)%> .
  385.                     </center></td>
  386.                 </tr>
  387.                 <tr>
  388.                   <td colspan="2"> <center>
  389.                       <font size="-1">
  390.                       <%DecimalFormat df=new DecimalFormat("###");
  391.                   String numNF=df.format(rs.getFloat("mark"));
  392.               out.print("("+numNF+"分)");%>
  393.                       </font></center></td>
  394.                 </tr>
  395.                 <tr>
  396.                   <td width="60%" align="right">
  397. <div align="right"><font size="-1">难度:</font></div></td>
  398.                   <td width="40%" align="left">
  399. <div align="left"><font size="-1"><%=rs.getString("PreHard")%></font></div></td>
  400.                 </tr>
  401.                 <tr>
  402.                   <td colspan="2"><div align="center"><%if(debug) out.print(rs.getString("ID"));%></div></td>
  403.                 </tr>
  404.                 <tr>
  405.                   <td colspan="2">&nbsp;</td>
  406.                 </tr>
  407.               </tbody>
  408.             </table></td>
  409.         <td align=left>
  410.          <%=jinghua.TransformString.DeleteBR(rs.getString("questtext"))%>
  411.  </td>
  412.       </tr>
  413.   <%}
  414.     rs.close();
  415.     stmt.close();
  416.     %>
  417.     </tbody>
  418.   </table>
  419.   <table cellspacing=0 cellpadding=8 width=650 border=0>
  420.     <tbody>
  421.     <tr>
  422.       <td align=center>
  423.             <!--begin botton-->
  424.             <input class=s02 type=submit value=提交 name=submit1>
  425.         &nbsp;&nbsp;
  426.         <input class=s02 type=reset value=重置 name=submit2>
  427.           <input name="studentid" type="hidden" id="studentid2" value="<%=studentID %>">
  428.           <input name="testresult" type="hidden" id="studentid2" value="<%=testIDs.toString()%>">
  429.         <!--end button-->
  430.       </td>
  431.     </tr>
  432.     </tbody>
  433.   </table>
  434.   <!--end test -->
  435.   <!--begin bottom -->
  436.   <TABLE
  437. style="BORDER-TOP: #dbdbdb 1px solid; MARGIN-TOP: 10px; MARGIN-BOTTOM: 10px; BACKGROUND-COLOR: #f6f6f6"
  438. cellSpacing=0 cellPadding=0 width="100%" border=0>
  439.   <TBODY>
  440.   <TR>
  441.     <TD align=middle colSpan=2 height=30>
  442.       <TABLE cellSpacing=0 cellPadding=0 width=750 border=0>
  443.         <TBODY>
  444.         <TR>
  445.           <TD><A href="http://jsptestonline.cosoft.org.cn/index.html"
  446.             target=_blank>关于我们</A> | <A
  447.             href="http://jsptestonline.cosoft.org.cn/contact/3_ywhz.html"
  448.             target=_blank>联系方式</A> | 网站地图 | <A
  449.             href="http://jsptestonline.cosoft.org.cn/about/service.html"
  450.             target=_blank>服务条款</A> | <A
  451.             href="http://jsptestonline.cosoft.org.cn/about/privacy.html"
  452.             target=_blank>隐私权保护</A> | <A
  453.             href="http://jsptestonline.cosoft.org.cn/about/copyright.html"
  454.             target=_blank>版权声明</A></TD>
  455.           <TD align=middle width=220>版权所有:<A href="http://jsptestonline.cosoft.org.cn/"
  456.             target=_blank>共创教育机构</A></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><!--end bottom --></form></CENTER></BODY></HTML>
  457. <%
  458. }catch(SQLException e){
  459.     out.print("<br>SQL Error:sql="+sql+"<br>"+e.toString());
  460. }catch(Exception e){
  461.     out.print(e.toString() );
  462. }
  463. finally{
  464.     DBCon.dropConnection();
  465. }
  466. %>