Sunday, 18 August 2013

How to get radio button values in Beans

How to get radio button values in Beans

I'm new to to server side coding and this happens to be my first project.
I have the following code in a jsp page. Now i forward the form to a
struts bean but i can't get the values of each radio button. I named them
but the name is appended with random number. How do i get these values in
the bean and check if the checked radio button is correct answer or not?
Statement st = DBConnection.DBConnection.DBConnect();
String query = "SELECT * FROM "+table_name+" ORDER BY RAND()
LIMIT 5";
ResultSet rs = st.executeQuery(query);
int i = 1;
while(rs.next()){
int q_no = rs.getInt(1);
String ques = rs.getString(2);
String opt1 = rs.getString(3);
String opt2 = rs.getString(4);
String opt3 = rs.getString(5);
String opt4 = rs.getString(6);
%>
<%=i%>. <%=ques%><br/>
<input type="radio" name="ans<%=q_no%>"
value="<%=opt1%>"/><%=opt1%><br/>
<input type="radio" name="ans<%=q_no%>"
value="<%=opt2%>"/><%=opt2%><br/>
<input type="radio" name="ans<%=q_no%>"
value="<%=opt3%>"/><%=opt3%><br/>
<input type="radio" name="ans<%=q_no%>"
value="<%=opt4%>"/><%=opt4%><br/>
<br/><br/>
<%
i++;
}

No comments:

Post a Comment