hi all i have created a jsp page for online exam here i have created a database to store all the question and answers ,used the database to fill all the radio button values,but whenever i retrieve the radio button value and compare it with the database value it is not comparing it...pls find the code below and give me some suggestions about it..
Index.jsp
<%@ page import="java.sql.*" %>
<%@ page import="java.lang.String.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h2>Online Exam</h2>
<form action="process.jsp" method="post">
<%
Connection con = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:derby://localhost:1527/student");
Statement st = con.createStatement();
ResultSet rs = null;
String sql = "select * from qtable";
st = con.createStatement();
rs = st.executeQuery(sql);
int i = 1;
while (rs.next()) {
String nn="p";
%>
<%out.println(rs.getString("qid") + ".");
out.println(rs.getString("question"));
%><br>
<input type="radio" name="<%= i%>" value="<%out.println(rs.getString("op1"));%>" /><%out.println(rs.getString("op1"));%>
<input type="radio" name="<%= i%>" value="<%out.println(rs.getString("op2"));%>" /><%out.println(rs.getString("op2"));%>
<input type="radio" name="<%= i%>" value="<%out.println(rs.getString("op3"));%>"/><%out.println(rs.getString("op3"));%><br><br>
<%out.println(nn); %>
<%
i++;
}
%>
<br><input type="submit" name="sub" value="submit"/>
</form>
<%
} catch (Exception e) {
out.println("TRY AGIN FAST........");
}
%>
</body>
</html>
Below contains the backend...
Quiz.JSP
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.lang.String.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
Connection con = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:derby://localhost:1527/student");
Statement st = con.createStatement();
String sql = "select * from qtable";
ResultSet rs = st.executeQuery(sql);
int i = 1, mark = 0;
while (rs.next()) {
String ans = request.getParameter("" + i);
String cans = rs.getString("cans");
out.println(cans);
out.println(ans);
if (cans.equals(ans)) {
out.println("works");
}
i++;
}
} catch (Exception e) {
out.println("GOT an Error Joe Please try again....." + e.getMessage());
}
%>
</body>
</html>