showquestion.jsp
上传用户:apbaoyuan
上传日期:2021-02-12
资源大小:1015k
文件大小:4k
- <%@page contentType="text/html;charset=GB2312"%>
- <%@page import="java.sql.*"%>
- <%@include file="opendata.jsp"%>
- <%!String printf(String str) //转换百分比格式
- {
- int index = 0;
- if ((index = str.indexOf(".")) != -1)
- str = str.substring(0, index) + "."
- + str.substring(index + 1, index + 3);
- return (str);
- }
- %>
- <html>
- <head>
- <title>在线答题</title>
- <link href="style.css" rel=stylesheet>
- </head>
- <body background="qq2.jpg">
- <form action="thanks.jsp" method="post">
- <%
- try{
- request.setCharacterEncoding("GB2312");
- sql = "SELECT Question,QuestionID,QuestionCount,Questionxx from questions where IsVisable = 1 ";
- rs = smt.executeQuery(sql);
- String question = null;
- int questionid = 0;
- int questioncount = 0;
- int questionxx=0;
- Statement _smt_ = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
- ResultSet _rs_;
- int i = 0; //题号
- int j; //选项标号
- int itemcount = 0;
- String percent = null;
- int itemid = 0;
- String item = null;
-
- while (rs.next())
- {
- i++;
- question = rs.getString(1);
- questionid = rs.getInt(2);
- questioncount = rs.getInt(3);
- questionxx=rs.getInt(4);
- j = 0;
- %>
- <table>
- <tr>
- <td><%=i%>.<%=question%>
- <%if(questionxx==1)
- {
- %>
- <font color=red>(单选题)
- <% }
- else
- {%>
- <font color=red>(多选题)
- <%
- }
- %>
- </td>
- </tr>
- <%
- if(questioncount==0)
- {
- out.print("暂时没有人参加投票");
- sql = "SELECT Item,ItemCount,ItemID from Items where QuestionID ='"+ questionid + "'";
- _rs_ = _smt_.executeQuery(sql);
- while (_rs_.next())
- {
- j++;
- item = _rs_.getString(1);
- itemcount = _rs_.getInt(2);
- itemid = _rs_.getInt(3);
- percent =printf(String.valueOf((double)itemcount/questioncount*100)+"0");
- if(questionxx==0)
- {
- %>
- <tr>
- <td><%=j%>.<%=item%> </td>
- <td>
- <input type=checkbox value="<%=itemid%>" name="<%=questionid%>">
- </td>
- </tr>
- <% }
- else
- {
- %>
- <tr>
- <td><%=j%>.<%=item%> </td>
- <td>
- <input type=radio value="<%=itemid%>" name="<%=questionid%>">
- </td>
- </tr>
- <% }
- }
-
- }
- else
- {
- out.print("共有"+questioncount+"参加投票");
- sql = "SELECT Item,ItemCount,ItemID from Items where QuestionID ="+ questionid;
- _rs_ = _smt_.executeQuery(sql);
- while (_rs_.next())
- {
- j++;
- item = _rs_.getString(1);
- itemcount = _rs_.getInt(2);
- itemid = _rs_.getInt(3);
- percent =printf(String.valueOf((double)itemcount/questioncount*100)+"0");
- if(questionxx==1)
- {
- %>
- <tr>
- <td><%=j%>.<%=item%> </td>
- <td>
- <input type=radio value="<%=itemid%>" name="<%=questionid%>">
- </td>
-
- <td>
- <table>
- <tr>
- <td bgcolor="blue" width=<%=Float.valueOf(percent)*2%>
- height=20></td>
- <td><%=itemcount%>人 <%=percent%> %</td>
- </tr>
- </table>
- </td>
- </tr>
- <% }
- else
- {
- %>
- <tr>
- <td><%=j%>.<%=item%> </td>
- <td>
- <input type=checkbox value="<%=itemid%>" name="<%=questionid%>">
- </td>
-
- <td>
- <table>
- <tr>
- <td bgcolor="blue" width=<%=Float.valueOf(percent)*2%>
- height=20></td>
- <td><%=itemcount%>人 <%=percent%> %</td>
- </tr>
- </table>
- </td>
- </tr>
- <% }
- }
-
- }
-
- %>
- </table>
- <p>
- <%
- }
-
- }
- catch (Exception e) {
- e.getStackTrace();
- }
- %>
-
- <hr>
- <div align=center>
- <INPUT class=buttonface type=submit value=提交 name=Submit>
- <INPUT class=buttonface type=reset value=重选 name=Submit2>
- </div>
- </form>
- </body>
- </html>