This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes JSP and the fly likes Online Examination-JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Online Examination-JSP" Watch "Online Examination-JSP" New topic
Author

Online Examination-JSP

Kailash karayat
Greenhorn

Joined: Jun 22, 2012
Posts: 10
Hi,

I want to create a online examination system.

i want to know to how to get questions 1 by 1 on the same jsp page and on clicking the submit button the result should be saved in database.

thanks in advance
Aniruddh Joshi
Ranch Hand

Joined: Jul 29, 2008
Posts: 275

You can call a servlet to get the next question when you click next.
The response will have the new question and will reload the same page.
Submit button can call another servlet to save answer to DB and response can load same page with same/next question.


Anrd
"One of the best things you could do is to simplify a larger application into a smaller one by reducing its process and complexity - Fowler"
Kailash karayat
Greenhorn

Joined: Jun 22, 2012
Posts: 10
hi,

what i have done till now is very simple.

i have created a servlet to fetch questions from the database.

servlet code.


and then i have stored the fetched records from the database to arraylist and then i am calling the arraylist in the jsp page.

code for jsp page.



to save the user response i am reloading the same servlet again and again to insert records in the database, my servlet for fetching records have also the code for saving the user's response. this is all what i have done till now, this is also working fine, but there are few issues.

1. i am not able to implement previous button.
2. if suppose my database has 20 questions, then for 19 questions it is saving the user's response and for the last question it is not saving the user's response in the database and giving error.
3.this is also not a good approach as my jsp has a lot of scriptlets, i want to remove this.

i have provided with you all the things which i have done till now now please help me in solving this issue.

thanks in advance.
Nat Pm
Greenhorn

Joined: Jan 21, 2013
Posts: 2
i tired your jsp code to display a question
but i am getting like hashcode values like as below

question 1.com.nata.exam.Dto.QuestionsDto@8b168b

A). com.nata.exam.Dto.QuestionsDto@1bab96e
B). com.nata.exam.Dto.QuestionsDto@1e3f60e
C). com.nata.exam.Dto.QuestionsDto@12f4771
D). com.nata.exam.Dto.QuestionsDto@fb87d1

please help me where i did mistake
sachin filenet
Greenhorn

Joined: Jan 02, 2015
Posts: 2
Last record is not storing in db : to solve this include itr.hasNext() method before calling next() methods

code of Examination.jsp

<%@page language="java" import="java.util.*" %>
<%@page language="java" import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome to OLExams</title>
<script type="text/javascript">
function fun1()
{
document.Examination.action="ResultServlet";
}

</script>
<script type="text/javascript">
function sachin()
{
// alert("sachin");
}

</script>


</head>
<body background="Australia.jpg">

<form name="form1" action="ExaminationServlet" method="post" target="_self">
<%String fname=(String)session.getAttribute("fname");%>
<div align="center">
<table width="80%" border="1" cellspacing="9" cellpadding="9">
<tr>
<td colspan="3">

</td>
</tr>
<tr>
<td colspan="3">
Good Luck <%=fname %>!!!
</td>
</tr>
<tr>
<td width="20%" height="350">
</td>
<td>

<%
int current = 0;
int previous = 0;
int num=1;
HttpSession sess=request.getSession();
Object qlist=sess.getAttribute("qlist");
List qlist1= (ArrayList)qlist;
ListIterator itr=qlist1.listIterator();
String qid=request.getParameter("qid");


if (request.getParameter("hidden") != null)
{
current = Integer.parseInt(request.getParameter("hidden"));
System.out.println("next "+current);
}

for (int i = 0; i < current; i++)
{

itr.next();
itr.next();
itr.next();
itr.next();
itr.next();
itr.next();
itr.next();

num++;
}



if(itr.hasNext())
{

%>
<p>
<input type="hidden" name="fname" value="<%=fname %>"/>
<input type="hidden" name="qid" value="<%=itr.next() %>"/>
<textarea name="question" cols="50" rows="5" Disabled Readonly id="question"><%=num %>.<%=itr.next() %>
</textarea>
</p>
<input type="hidden" name="corans" value="<%=itr.next() %>"/>

<p>
A).<input type="radio" name="option" value="A"><%=itr.next()%>
</p>
<p>
B).<input type="radio" name="option" value="B"><%=itr.next()%>
</p>
<p>
C).<input type="radio" name="option" value="C"><%=itr.next() %>
</p>
<p>
D).<input type="radio" name="option" value="D"><%=itr.next()%>
</p>

<BR/>
<p>

<input type="hidden" name="previous" value="<%=current-1%>"/>
<input type="submit" VALUE="previous">
<input type="hidden" name="hidden" value="<%=current+1 %>"/>
<input type="submit" VALUE="next" onclick="sachin()">

</p>
</form>
<input type="button" VALUE="Submit Exam" onclick="location.href='ResultServlet'"/>
<%
}

%>
</td>
<td width="20%" height="380"> </td>
</tr>
<tr>
<td colspan="3">

</td>
</tr>
</table>
</div>

</form>
</body>
</html>
sachin filenet
Greenhorn

Joined: Jan 02, 2015
Posts: 2
Hi this is sachin again..

Previous button is not working please anyone solve the problem.
Thanks in advance.
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 1404
    
  14

I'm obliged to point out several critical problems with your design. First, that's way too much code in the servlet. It should contain maybe 10 lines of code at the most. All that database code belongs in a Data Access Object that returns the data in a collection. Second, get rid of all that Java code in the JSP. There should be no code in a JSP, they are for generating the view only. All processing should take place in Java classes before the data is sent to the JSP. That scriptlet technique that you're using is 13 years old. Throw it away.


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12982
    
    5
Just to echo that good advice, you will find it a LOT easier to debug your application if all requests go to a servlet instead of a JSP page. If this was my problem I would have provision in that servlet for logging exactly what each request contains.

Bill
Mahtab Alam
Ranch Hand

Joined: Mar 28, 2012
Posts: 354

I have one question on online exam app.

I am showing a timer on the question page , the timer works fine.

But the problem is if user refreshes the page , the timer starts from the beginning.
I don`t want that , Even if user refresh the page it should start from previous time.

So what I am thinking is , when user refreshes the page I will send the time parameters( minute & seconds) to servlet .
And in the jsp page I will start the timer from the same param returned by servlet .

One such is implemented here at certpal.com


http://www.mahtabalam.net , Oracle Java Programmer , Oracle SQL Expert , Oracle Java Web Component Developer
Mahtab Alam
Ranch Hand

Joined: Mar 28, 2012
Posts: 354

I have created one Quiz application using JSP Servlet.

While making this small app I learnt a lot specially maintaining sessions.

You can read about it and download the code Online Quiz Application Using JSP Servlet

I am thinking of adding below functionalities into it.

1. Each quiz can have different number of questions

2. Each question can have different number of options

3. A question can have multiple correct options

4. Implementing a timer for the quiz

5. Maintaining a history of the user; like how many tests a user have taken in the past and his score

6. Randomizing the order of questions presented to the user

7. Giving the user option to review his answers before submitting the test for evaluation

8. A dropdown box to jump to any question in between the test rather then clicking next button multiple times.

Mahtab Alam
Ranch Hand

Joined: Mar 28, 2012
Posts: 354

Can we handle the browser refresh button click using javascript.
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 1404
    
  14

Mahtab Alam wrote:Can we handle the browser refresh button click using javascript.

Don't try to alter the expected behavior of the browser. The best way to solve your timer problem is by using AJAX to make requests to the server.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Online Examination-JSP
 
It's not a secret anymore!