title: Multiple choice questions in jsp
body: <p>I am developing a webpage where i am going to conduct a small quiz based on plain JSP-MsAccess
  connection.But when I run my quiz and when I answer a question the result is applied to all questions means if I get first question right then my score is 10 and if I get first answer wrong my score is 0.
  code:</p>
  
  <pre><code>&lt;%@ page import="java.sql.*" %&gt;
  
  &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd"&gt;
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
  &lt;title&gt;JSP Page&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;% 
  String ans=" ";
  if(request.getParameter("correctAns")!=null)
  {
      ans=request.getParameter("correctAns").toString();
  }
  
  
  Connection conn = null;
  
  Statement st = null;
  
  ResultSet rs = null;
  
  String id=request.getParameter("id");
  System.out.println("id:"+id);
  
  int i=1;
  
  String s,g;
  
  int count=0;
  
  try {
  
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   conn = DriverManager.getConnection("jdbc:odbc:qdsn");
   rs = null;
  
   st = conn.createStatement();
  
  //for(i=1;i&lt;=2;i++)
  // {
  rs = st.executeQuery("select * from exam");
  
  while(rs.next()) {
  %&gt;
  
  
  &lt;br/&gt;
  &lt;center&gt;
  
  &lt;table border="1" width="500px" bgcolor="pink" cellspacing="0" cellpadding="0"&gt;
    &lt;tr&gt;
      &lt;td width="100%"&gt;
  
  &lt;form name="form1"&gt;
  
   &lt;h2 align="center"&gt;&lt;font color="red"&gt;Online Quiz Application&lt;/font&gt;&lt;/h2&gt;
  
  &lt;b&gt;Select Correct Answer&lt;/b&gt;
          &lt;table border="0" width="500px" cellspacing="2" cellpadding="4"&gt;
   &lt;tr&gt;
  
  &lt;td width="50%"&gt; Question:&lt;/td&gt;
  &lt;input type="hidden" name="correctAns" value="&lt;%=rs.getString(6)%&gt;" /&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;%= rs.getString("quest") %&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;
  
  1: &lt;input type="radio" name="a" value= "QA" /&gt;&lt;/td&gt;
      &lt;td&gt;&lt;%= rs.getString("QA") %&gt;&lt;/td&gt;&lt;/tr&gt; 
  &lt;tr&gt;
  &lt;td&gt;
  2: &lt;input type="radio" name="a" value="QB" /&gt;&lt;/td&gt;
  &lt;td&gt;&lt;%= rs.getString("QB") %&gt;&lt;/td&gt;&lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt;
  3: &lt;input type="radio" name="a" value="QC" /&gt;&lt;/td&gt;
  &lt;td&gt;&lt;%= rs.getString("QC") %&gt; &lt;/td&gt;&lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt;
  4: &lt;input type="radio" name="a" value="QD" /&gt; &lt;/td&gt;
  &lt;td&gt; &lt;%= rs.getString("QD") %&gt; &lt;/td&gt;&lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt;
  &lt;center&gt;
     &lt;input type="submit" value="Submit" name="submit"&gt;&lt;/center&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;/table&gt;
  
  &lt;/form&gt;
   &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/center&gt;
  &lt;/body&gt;
  &lt;% g=request.getParameter("a");
  %&gt;
  &lt;% 
  if(g.equals(ans)){
  
  count++;
  }
  
  %&gt;
  
  
  
  &lt;%
  }}
  // }
  catch (Exception ex) {
  ex.printStackTrace();
  
  %&gt;
  
  &lt;%
  } finally {
  if (rs != null) rs.close();
  if (st != null) st.close();
  if (conn != null) conn.close();
  }
  out.println("Score="+count);
  %&gt;
  
  
  &lt;/html&gt;
  </code></pre>