showquestion.jsp
上传用户:apbaoyuan
上传日期:2021-02-12
资源大小:1015k
文件大小:4k
源码类别:

Jsp/Servlet

开发平台:

HTML/CSS

  1. <%@page contentType="text/html;charset=GB2312"%>
  2. <%@page import="java.sql.*"%>
  3. <%@include file="opendata.jsp"%>
  4. <%!String printf(String str) //转换百分比格式
  5. {
  6. int index = 0;
  7. if ((index = str.indexOf(".")) != -1)
  8. str = str.substring(0, index) + "."
  9. + str.substring(index + 1, index + 3);
  10. return (str);
  11. }
  12. %>
  13. <html>
  14. <head>
  15. <title>在线答题</title>
  16. <link href="style.css" rel=stylesheet>
  17. </head>
  18. <body background="qq2.jpg">
  19. <form action="thanks.jsp" method="post">
  20. <%
  21. try{
  22. request.setCharacterEncoding("GB2312");
  23. sql = "SELECT Question,QuestionID,QuestionCount,Questionxx from questions where IsVisable = 1 ";
  24. rs = smt.executeQuery(sql);
  25. String question = null;
  26. int questionid = 0;
  27. int questioncount = 0;
  28. int questionxx=0;
  29. Statement _smt_ = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
  30. ResultSet _rs_;
  31. int i = 0; //题号
  32. int j; //选项标号
  33. int itemcount = 0;
  34. String percent = null;
  35. int itemid = 0;
  36. String item = null;
  37. while (rs.next()) 
  38. {
  39. i++;
  40. question = rs.getString(1);
  41. questionid = rs.getInt(2);
  42. questioncount = rs.getInt(3);
  43. questionxx=rs.getInt(4);
  44. j = 0;
  45. %>
  46. <table>
  47. <tr>
  48. <td><%=i%>.<%=question%>
  49.    <%if(questionxx==1) 
  50.      {
  51.    %>
  52.        <font color=red>(单选题)
  53.    <% }
  54.    else  
  55.      {%>
  56.        <font color=red>(多选题)
  57.    <%
  58.       }
  59.    %>
  60. </td>
  61. </tr>
  62. <%
  63. if(questioncount==0)
  64. {
  65.   out.print("暂时没有人参加投票");
  66. sql = "SELECT Item,ItemCount,ItemID from Items where QuestionID ='"+ questionid + "'";
  67. _rs_ = _smt_.executeQuery(sql);
  68.          while (_rs_.next()) 
  69.          {
  70.  j++;
  71.  item = _rs_.getString(1);
  72.  itemcount = _rs_.getInt(2);
  73.   itemid = _rs_.getInt(3);
  74.   percent =printf(String.valueOf((double)itemcount/questioncount*100)+"0");
  75.   if(questionxx==0)
  76.   {
  77. %>
  78. <tr>
  79. <td><%=j%>.<%=item%> </td>
  80. <td>
  81. <input type=checkbox  value="<%=itemid%>" name="<%=questionid%>">
  82. </td>
  83. </tr>
  84. <%           }
  85.              else
  86.              {
  87. %>
  88.     <tr>
  89.    <td><%=j%>.<%=item%> </td>
  90.    <td>
  91.    <input type=radio  value="<%=itemid%>" name="<%=questionid%>">
  92.    </td>
  93. </tr>
  94. <%           }
  95.           } 
  96.           
  97.      }
  98.      else 
  99.      {     
  100.      out.print("共有"+questioncount+"参加投票");
  101.      sql = "SELECT Item,ItemCount,ItemID from Items where QuestionID ="+ questionid; 
  102.  _rs_ = _smt_.executeQuery(sql);
  103.      while (_rs_.next()) 
  104.     {
  105.  j++;
  106.  item = _rs_.getString(1);
  107.  itemcount = _rs_.getInt(2);
  108.  itemid = _rs_.getInt(3);
  109.  percent =printf(String.valueOf((double)itemcount/questioncount*100)+"0");
  110.  if(questionxx==1)
  111.    {
  112.     %>
  113.                  <tr>
  114.  <td><%=j%>.<%=item%> </td>
  115.  <td>
  116.  <input type=radio  value="<%=itemid%>" name="<%=questionid%>">
  117.  </td>
  118.  <td>
  119.    <table>
  120.  <tr>
  121.  <td bgcolor="blue" width=<%=Float.valueOf(percent)*2%>
  122. height=20></td>
  123.  <td><%=itemcount%>人  &nbsp;&nbsp;<%=percent%> %</td>
  124.  </tr>
  125.    </table>
  126.  </td>
  127.  </tr>
  128. <%           }
  129.              else 
  130.    {
  131.     %>
  132.      <tr>
  133. <td><%=j%>.<%=item%> </td>
  134. <td>
  135. <input type=checkbox  value="<%=itemid%>" name="<%=questionid%>">
  136. </td>
  137.     <td>
  138. <table>
  139. <tr>
  140. <td bgcolor="blue" width=<%=Float.valueOf(percent)*2%>
  141. height=20></td>
  142. <td><%=itemcount%>人  &nbsp;&nbsp;<%=percent%> %</td>
  143. </tr>
  144. </table>
  145. </td>
  146.     </tr>
  147. <%            }
  148. }
  149. }
  150. %>
  151. </table>
  152. <p>
  153. <%
  154. }
  155.  
  156. }
  157. catch (Exception e) {
  158. e.getStackTrace();
  159. }
  160. %>
  161. <hr>
  162. <div align=center>
  163. <INPUT class=buttonface type=submit value=提交 name=Submit>
  164. <INPUT class=buttonface type=reset value=重选 name=Submit2>
  165. </div>
  166. </form>
  167. </body>
  168. </html>