How to generate getter and setter for radio buttons in Struts
I'm working on an online exam. Here i have 5 groups of radio buttons and
the name attribute is appended with a random number(which is the PK in
MySql DB). How do i generate getter and setter methods in my Form Bean for
these radio buttons such that i can check the answers from each group
against the DB.
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++;
}
PS:I know struts 1.3 is obsolete but I'm being taught from bottom up. And
the SQL injections are not a worry right now.
No comments:
Post a Comment