0
<%@ page import="java.sql.*" %>


<!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>
<%
String ans=" ";
if(request.getParameter("correctAns")!=null)
{
ans=request.getParameter("correctAns").toString();
}



Connection con = null;


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = java.sql.DriverManager.getConnection("jdbc:odbc:sid");
Statement st = null;
ResultSet qrst;
ResultSet rs = null;


String id=request.getParameter("id");
System.out.println("id:"+id);


int i=1;


String s,g;


int count=0;


try {


st = con.createStatement();
//for(i=1;i<=2;i++)
// {
rs = st.executeQuery("select * from quiz");


while(rs.next()) {
%>


<br>
<br/>
<center>


<table border="1" width="500px" bgcolor="pink" cellspacing="0" cellpadding="0">
<tr>
<td width="100%">


<form name="form1">


<h2 align="center"><font color="red">Online Quize Application</font></h2>


<b>Select Correct Answer</b>
<table border="0" width="500px" cellspacing="2" cellpadding="4">
<tr>


<td width="50%"> Question:</td>
<input type="hidden" name="correctAns" value="<%=rs.getString(7)%>" />
<tr>
<td><%= rs.getString("quest") %></td></tr>
<tr>
<td>


1: <input type="radio" name="a" value= "QA" /></td>
<td><%= rs.getString("QA") %></td></tr>
<tr>
<td>
2: <input type="radio" name="a" value="QB" /></td>
<td><%= rs.getString("QB") %></td></tr>


<tr>
<td>
3: <input type="radio" name="a" value="QC" /></td>
<td><%= rs.getString("QC") %> </td></tr>


<tr>
<td>
4:    <input type="radio" name="a" value="QD" /> </td>
<td> <%= rs.getString("QD") %> </td></tr>


<tr>
<td>
<center>
<input type="submit" value="Submit" name="submit"></center></td></tr>
</table>


</form>
</td>
</tr>
</table>
</center>
</body>
<% g=request.getParameter("a");
%>
<%
if(g.equals(ans)){


count++;
out.println("Correct");


}
else
out.println("False");
%>


<%
}}
// }
catch (Exception ex) {
ex.printStackTrace();


%>


<%
} finally {
if (rs != null) rs.close();
if (st != null) st.close();
if (con != null) con.close();
}
out.println("Score="+count);
%>


</html>

Edited by Nick Evan: Fixed formatting

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by masijade
0

Sorry, but I, for one, am not going to even try to decipher these scriptlets. You should not be using scriptlets, that is the technology from over a decade ago. Go through the JEE6 tutorials and learn to do this right.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.