Guest User

Untitled

a guest
Jan 5th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. <%@ page import="java.sql.*" %>
  2. <%@ page import="java.io.*" %>
  3. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  4. pageEncoding="ISO-8859-1"%>
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  6. <html>
  7. <head>
  8. <style></style>
  9. <%
  10. int i=1;
  11. String url = "jdbc:mysql://127.0.0.1:3306/Quiz";
  12. String username1="root";
  13. String password1="root";
  14. PreparedStatement st = null;
  15. ResultSet results = null;
  16.  
  17. int iQuestionID=3;
  18. try {
  19.  
  20. Class.forName("com.mysql.jdbc.Driver");
  21. Connection con= DriverManager.getConnection(url,username1,password1);
  22. String sql="SELECT Questions.Question, Questions.option1, Questions.option2,Questions.option3, Questions.option4,Questions.correctanswer FROM Questions order by RAND() limit ?";
  23. st = (PreparedStatement) con.prepareStatement(sql);
  24. st.setInt(1,iQuestionID);
  25. results = st.executeQuery();
  26.  
  27. while (results.next()) {
  28. String r1, r2, r3, r4, r5,r6;
  29. r1 = results.getString(1);
  30. r2 = results.getString(2);
  31. r3 = results.getString(3);
  32. r4 = results.getString(4);
  33. r5 = results.getString(5);
  34. r6 = results.getString(6);
  35. %>
  36.  
  37. <br/>
  38. <center>
  39.  
  40.  
  41. <form name="form1" method="post" action="Results.jsp" >
  42. <table border="1" width="500px" bgcolor="white" cellspacing="0" cellpadding="0">
  43. <tr>
  44. <td width="100%">
  45.  
  46.  
  47.  
  48. <h2 align="center"><font color="red">Online Quiz Application</font></h2>
  49.  
  50. <b>Select Correct Answer</b>
  51. <table border="0" width="500px" cellspacing="2" cellpadding="4">
  52. <tr>
  53.  
  54. <td width="50%"> Question:</td>
  55. <td><input type="hidden" name="correctAns<%= i %>" value="<%= results.getString(6) %>" /></td>
  56. </tr>
  57. <tr>
  58. <td><%= results.getString(1) %></td></tr>
  59. <tr>
  60. <td>
  61.  
  62. 1: <input type="radio" name="a<%= i %>" id="a<%= i %>" value="<%= results.getString(2) %>" /></td>
  63. <td><%= results.getString(2) %></td></tr>
  64. <tr>
  65. <td>
  66. 2: <input type="radio" name="a<%= i %>" id="a<%= i %>" value="<%= results.getString(3) %>" /></td>
  67. <td><%= results.getString(3) %></td></tr>
  68.  
  69. <tr>
  70. <td>
  71. 3: <input type="radio" name="a<%= i %>" id="a<%= i %>" value="<%= results.getString(4) %>" /></td>
  72. <td><%= results.getString(4) %> </td></tr>
  73.  
  74. <tr>
  75. <td>
  76. 4: <input type="radio" name="a<%= i %>" id="a<%= i %>" value="<%= results.getString(5) %>" /> </td>
  77. <td> <%= results.getString(5) %> </td></tr>
  78. </table>
  79. </td>
  80. </tr>
  81.  
  82. </table>
  83.  
  84.  
  85. <br/>
  86. <% if (i==iQuestionID)
  87. {
  88. %>
  89. <INPUT type = "submit" name="addSubmit" value = "Press to Submit">
  90. <% } %>
  91.  
  92. </form>
  93. </center>
  94. <%
  95.  
  96. i++;
  97. }
  98. results.close();
  99. con.close();
  100.  
  101. }catch (Exception ex) {
  102. ex.printStackTrace();
  103.  
  104.  
  105. }finally {
  106. } %>
  107.  
  108.  
  109.  
  110. </body>
  111. </html>
  112.  
  113. <%
  114. String id[]= new String [5];
  115. for (int i=1;i<5; i++)
  116. {
  117. id[i]=request.getParameter("a"+i);
  118. out.println(id[i]);
  119. }
  120.  
  121. %>
Add Comment
Please, Sign In to add comment