Three tier application using Tomcat to conduct online examination in JSP

online.jsp

 

<%@ page import=”java.sql.*” %>

<%@ page import=”java.util.*” %>

<head><title>Online Examination in JSP</title></head>

<body>

<form method=”post”>

 

<b> 1. Who is the inventor of C Language?   <br><br>

<input type=”radio” name=”r1″ value=”Dennis” checked=”false”>Dennis

<input type=”radio” name=”r1″ value=”franklin” checked=”false”> franklin

 

<input type=”radio” name=”r1″ value=”Bjarne” checked=”false”> Bjarne

<input type=”radio” name=”r1″ value=”Patric” checked=”false”> Patric <br><br>

 

2. Who is the inventor of C++  Language? <br><br>

<input type=”radio” name=”r2″ value=”Dennis” checked=”false”> Dennis

<input type=”radio” name=”r2″ value=”franklin” checked=”false”> franklin

<input type=”radio” name=”r2″ value=”Bjarne” checked=”false”> Bjarne

<input type=”radio” name=”r2″ value=”Patric” checked=”false”> Patric <br> <br>

 

3. Who is the inventor of Java Language? <br><br>

<input type=”radio” name=”r3″ value=”Dennis” checked=”false”> Dennis

<input type=”radio” name=”r3″ value=”franklin” checked=”false”> franklin

<input type=”radio” name=”r3″ value=”Bjarne” checked=”false”> Bjarne

<input type=”radio” name=”r3″ value=”Patric” checked=”false”> Patric <br> <br>

</b>

<input type=”submit”  value=”submit”>

</form>

<%

try

{

Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);

Connection connection = DriverManager.getConnection(“jdbc:odbc:bpl”, “”, “”);

Statement statement = connection.createStatement();

ResultSet rs = statement.executeQuery(“select * from exam”);

Enumeration e = request.getParameterNames();

int count =0;

String answer;

String ans[] = new String[3];

int i=2;

while(e.hasMoreElements())

{

String name =(String) e.nextElement();

String pvalue = request.getParameter(name);

ans[i] = pvalue;

i–;

}

i=0;

while(rs.next())

{

out.println(“<br>”);

answer = rs.getString(“answer”);

if(answer.equals(ans[i]))

count = count + 1;

i++;

}

if(count == 3)

out.println(“<br> <B> Congratulations Your score is </B>” +count);

else

out.println(“<br> <B>Try Again: Your Score is </B>” + count);

}

catch(Exception e1)

{

out.println(“Exception caught: ” + e1.getMessage());

}

%>

</BODY>

</HTML>

 Database

exam.accdb

field name: answer

field value 1: Dennis

Field value 2: Bjarne

Field value 3:  Patrick

STEPS TO GET OUTPUT:

 

1)    Type and Save the above the coding as online.jsp in

C:\Program Files\Apache Group\Tomcat 4.1\webapps\examples\jsp directory

2)    To run the TOMCAT 4.1

3)    Open the Internet Explorer and give request like

http://localhost:8080/examples/jsp/online.jsp.

4)    To get the output.

 

Note: Ensure that you should create a Data Source Name and create exam in either

MS-ACCESS or ORACLE, which contains only one column “answer” with 3 rows

(Objective answers).