Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack (1) Thread Tools Display Modes
Old 16-11-2008, 07:35 PM   1 links from elsewhere to this Post. Click to view. #1 (permalink)
Broken In
 
sganesh's Avatar
 
Join Date: Nov 2007
Location: Chennai
Posts: 113
Default Need Help in creating online quiz application using JSP


Hi,
i am creating online Quiz application using JSP and MySQl ,Apache 6 in Netbeans IDE.
i am able to successfully display first question from database,and can say the answer is correct or not,,but i can't implement the program further ,in such way that when clicking next button ,new question gets displayed and score calculated there after!,
index.jsp
----------------------------------------------------------------------------------------------------
<%--
Document : start
Created on : Nov 16, 2008, 2:58:18 PM
Author : Ganesh
--%>
<%@ 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=" ";
Connection conn = null;
Statement st = null;
ResultSet rs = null;
int i=1;
String s,g;
int count=0;
try {

//Class.forName("com.mysql.jdbc.Driver").newInstance ();
Class.forName("com.mysql.jdbc.Driver").newInstance ();
conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/MyNewDatabase","root","");

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


while(rs.next()) {
%>



<form name="form1">

Question:
<h3> <%= rs.getString("quest")%></h3>

1: <%= rs.getString("a") %> <input type="radio" name="a" value= "a" />

2: <%= rs.getString("b") %> <input type="radio" name="a" value="b" />

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

4: <%= rs.getString("d") %> <input type="radio" name="a" value="d" />
<input type="submit" value="OK">
</form>

<% g=request.getParameter("a");
%>
<% ans= rs.getString("ans");
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 (conn != null) conn.close();
}
out.println("Score="+count);
%>


</html>
------------------------------------------------------------------------------------------------------
contents of database
mySql-->select * from quiz;
quest a b c d e ans
What is capital of india Chennai Mumbai Delhi bangalore c 1
What is capital of tamil nadu Chennai madurai trichy coim a 2
--------------------------------------------------------------------------------------------
i need Some ideas to build this project !!!
sganesh is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 16-11-2008, 11:25 PM   #2 (permalink)
In The Zone
 
Join Date: Oct 2006
Location: Mumbai
Posts: 365
Default Re: Need Help in creating online quiz application using JSP

what you are doing is not a best practice you should write business logic in java
try Struts 2 it is quite easy to learn and very effective in developing any kind of application in very short time.
__________________
Dhiraj Thakur
thakur.dheeraj(@)gmail.com
Desi-Tek.com is offline  
Old 17-11-2008, 09:53 AM   #3 (permalink)
CAFEBABE
 
chandru.in's Avatar
 
Join Date: Mar 2008
Location: Bangalore
Posts: 474
Default Re: Need Help in creating online quiz application using JSP

@sganesh

What Desi-Tek told is right. What you are doing is completely bad way of doing it and IMHO it is a reason you are stuck. Even if you don't want to use any framework, I'd suggest you to read up on MVC architecture. It will make your life a breeze once you learn.

A simple MVC for your case would be writing a servlet, which invokes quiz validation code from another simple class. All JSPs can post to this servlet and the servlet should dispatch to appropriate JSP after validation.

I personally like not using frameworks for simple apps and for complex apps I prefer JSF.
__________________
Chandru

http://tuxychandru.blogspot.com
chandru.in is offline  
Old 17-11-2008, 11:57 AM   #4 (permalink)
Broken In
 
sganesh's Avatar
 
Join Date: Nov 2007
Location: Chennai
Posts: 113
Default Re: Need Help in creating online quiz application using JSP

ok fien,i thought to reimplement the project in Struts,
Thanks!
sganesh is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


LinkBacks (?)
LinkBack to this Thread: http://www.thinkdigit.com/forum/programming/102235-need-help-creating-online-quiz-application-using-jsp.html
Posted By For Type Date
in creating online quiz application using JSP Programming Question This thread Refback 23-06-2010 02:41 PM

Similar Threads
Thread Thread Starter Forum Replies Last Post
Errors !!! -> A rant about online application errors Bandu Chit-Chat 5 22-08-2008 11:15 PM
IT quiz maharajadhiraj QnA (read only) 1 19-10-2005 07:59 PM
Please Help ! A big Quiz really! huzaifa b arab QnA (read only) 12 18-05-2005 03:53 AM

 
Latest Threads
- by gforz
- by soumya
- by Sujeet
- by icebags
- by Charan

Advertisement




All times are GMT +5.5. The time now is 02:59 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2