Hi All,

I am trying to pass the value of selected radio button from one jsp page to another but my code is not working.

Below is my code:-

Code:
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style></style>
<% 
        int i=1;
        String url = "jdbc:mysql://127.0.0.1:3306/Quiz";
        String username1="root";
        String password1="root";
        PreparedStatement st = null;
        ResultSet results = null;
 
         int iQuestionID=3;
            try {
 
                Class.forName("com.mysql.jdbc.Driver");
                Connection con= DriverManager.getConnection(url,username1,password1);
                String sql="SELECT  Questions.Question, Questions.option1, Questions.option2,Questions.option3, Questions.option4,Questions.correctanswer FROM Questions order by RAND() limit ?";
                st = (PreparedStatement) con.prepareStatement(sql);
                 st.setInt(1,iQuestionID);
                results = st.executeQuery(); 
 
                while (results.next()) {
    String r1, r2, r3, r4, r5,r6;
    r1 = results.getString(1);
    r2 = results.getString(2);
    r3 = results.getString(3);
    r4 = results.getString(4);
    r5 = results.getString(5);
    r6 = results.getString(6);
%>
 
<br/>
<center>
 
 
<form name="form1"  method="post" action="Results.jsp" > 
<table border="1" width="500px" bgcolor="white" cellspacing="0" cellpadding="0">
<tr>
<td width="100%"> 
 
 
 
<h2 align="center"><font color="red">Online Quiz Application</font></h2>
 
<b>Select Correct Answer</b>
<table border="0" width="500px" cellspacing="2" cellpadding="4">
<tr>
 
<td width="50%"> Question:</td>
<td><input type="hidden" name="correctAns<%= i %>" value="<%= results.getString(6) %>" /></td>
</tr>
<tr>
<td><%= results.getString(1) %></td></tr>
<tr>
<td>
 
1: <input type="radio" name="a<%= i %>"  id="a<%= i %>" value="<%= results.getString(2) %>" /></td>
<td><%= results.getString(2) %></td></tr> 
<tr>
<td>
2: <input type="radio" name="a<%= i %>" id="a<%= i %>" value="<%= results.getString(3) %>" /></td>
<td><%= results.getString(3) %></td></tr>
 
<tr>
<td>
3: <input type="radio" name="a<%= i %>" id="a<%= i %>" value="<%= results.getString(4) %>" /></td>
<td><%= results.getString(4) %> </td></tr>
 
<tr>
<td>
4: <input type="radio" name="a<%= i %>" id="a<%= i %>" value="<%= results.getString(5) %>" /> </td>
<td> <%= results.getString(5) %> </td></tr>
</table>
</td>
</tr>
 
</table>
 
 
<br/>
            <% if (i==iQuestionID)
                        {
                    %>
    <INPUT type = "submit" name="addSubmit" value = "Press to Submit">
    <% } %>
 
</form>
</center>
<%
 
i++;
} 
results.close();
con.close();
 
}catch (Exception ex) {
    ex.printStackTrace();
 
 
    }finally {     
    } %>
 
 
 
</body>
</html>

And the code in Results.Jsp

<%
String id[]= new String [5];
for (int i=1;i<5; i++)
{
id[i]=request.getParameter("a"+i);
out.println(id[i]);
}

%>


But in Results.jsp , I am getting null values.

I even tried the code with servlets.I was able to display the questions of quiz but I am unable to fetch the value of selected radio button.

Any help in correcting the above jsp code so that I can fetch the value of selected radio button will be much appreciated.

Thanks