<%@ page import = "java.util.*"%>
<%@ page import = "java.lang.*"%>
<%@ page import="java.sql.*" %>
<%@ page language="java" import="java.sql.*" errorPage="" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
    String ans=" ";
        Connection conn = null;
        String url = "jdbc:mysql://localhost:3306/";
        String db = "test";
        String driver = "com.mysql.jdbc.Driver";
        String userName ="root";
        String pass="password";
        Statement st = null;
        ResultSet qrst;
        ResultSet rs = null;

    String a,b;
   int count = 0;
    int items = 0 ;

try {

    conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "password");

    st = conn.createStatement();
    rs = st.executeQuery("select * from questionnaires");

while(rs.next()) {

<table border="1" width="500px" bgcolor="white" cellspacing="0" cellpadding="0">
<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">
<td width="50%"> Question Number: <%= rs.getString("qid")%></td>

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

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

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

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

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







catch (Exception ex) {


} finally {
if (rs != null) rs.close();
if (st != null) st.close();
if (conn != null) conn.close();


if(count <= items)
        //String strcount = Integer.toString(count);
        //String stritems = Integer.toString(items);
        //out.println("Score :" . count . "/" .items);

        out.print("Score :");

Hello, I'm creating a simple Online Exam System but i'm having some problem with my codes. I want to count all the correct answers and wrong answers. How should I do it? I mean, what code should I use? I'm a beginner in jsp. Please help. Thank you so much.

Recommended Answers

All 3 Replies

my advice: you seem to know the basics of jsp, no head over to servlets.
that should get all of that java code out of the jsp file, and make it a lot easier to work with.

Oh thank you for that sir, But I just wanna ask what should I use because in that code that I'm doing it only checks 1 by 1. Maybe theres a code to check all at once but idk what should I use.

they're all different components, so I don't see how you would put a 'check all' in there, without writing a check all method that checks them one by one

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.