wood burning stoves*
The moose likes HTML, CSS and JavaScript and the fly likes Inter Frame communication in quiz application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Inter Frame communication in quiz application" Watch "Inter Frame communication in quiz application" New topic
Author

Inter Frame communication in quiz application

bala kannan
Greenhorn

Joined: Jan 22, 2012
Posts: 5
Hi All,

I am trying to develop a quiz application based on MVC architecture using JSP and servlets. I have a frame where left side displays the questions and right side displays the set of buttons(total no of questions). When i click on "2" button, its not overwriting the left pane, instead its appending with the left one and displaying 1,2 questions. When i click on 3rd button, the left pane is not getting overwritten. In my servlets i am using request Dispatcher to forward to Jsp which will display the frame. Can you please hel out here. Below is my code

//Frame displaying left side question and right side buttons


<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<frameset cols="60%,*">
<frame src="questiondisplay.jsp" name="displayquestion"/>
<frame src="questionset.jsp" name="questionset"/>
</frameset>
</html>

------------------------------------------------------
//Page with buttons

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<script type="text/javascript">


</script>
<form name="fetch" method="post" action="questionDisplay">
<input type="hidden" name="btn"/>
<table>
<%
//Object o=request.getAttribute("size");
//Integer size=(Integer)request.getAttribute("size");
//int no=size.intValue();

for(int i=1;i<=25;i++) {%>
<tr>
<td>
<input type="button" value="<%=i %>" onclick="{document.fetch.btn.value=this.value;document.fetch.submit();}"/>
</td>
</tr>
<%}
%>
</table>
</form>
</body>
</html>
------------------------------------

//Page to display question

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form name="display">
<jsp:useBean id="ques" scope="application" class="questiondisplay.FetchQuestion"/>
<table align="center" width="45%">
<tr>
<td>
<jsp:getProperty name="ques" property="question"/>
</td>
</tr>
<tr>
<td>
<input type="radio"/>
</td>
<td>
<jsp:getProperty name="ques" property="option1"/>
</td>
</tr>
<tr>
<td>
<input type="radio"/>
</td>
<td>
<jsp:getProperty name="ques" property="option2"/>
</td>
</tr>
<tr>
<td>
<input type="radio"/>
</td>
<td>
<jsp:getProperty name="ques" property="option3"/>
</td>
</tr>
<tr>
<td>
<input type="radio"/>
</td>
<td>
<jsp:getProperty name="ques" property="option4"/>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Next"/>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Previous"/>
</td>
</tr>
<tr>
<td>
<input type="submit" value="submit"/>
</td>
</tr>
</table>
</form>
</body>
</html>
-------------------------------------------------------

//Servlet code

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
int btnvalue=Integer.parseInt(request.getParameter("btn"));
String username=(String)request.getSession().getAttribute("username");

try{
database db=new database();
Connection conn=db.getConnection();
Statement stmt=conn.createStatement();
String query="select * from "+username+" where qno="+btnvalue;
ResultSet rset=stmt.executeQuery(query);
rset.next();
qno=rset.getInt(1);
question=rset.getString("question");
option1=rset.getString("option1");
option2=rset.getString("option2");
option3=rset.getString("option3");
option4=rset.getString("option4");
FetchQuestion qdisplay=new FetchQuestion();
qdisplay.setQuestionInfo(qno, question, option1, option2, option3, option4);
request.getSession().setAttribute("ques",qdisplay);
RequestDispatcher send=request.getRequestDispatcher("questions.jsp");
send.forward(request,response);
//response.sendRedirect("questions.jsp");
}catch(Exception e){
e.printStackTrace();
}
}
------------------------------------------

bala kannan
Greenhorn

Joined: Jan 22, 2012
Posts: 5
I request some one to suggest a solution here as i am stuck with no way forward. My requirement. When i click the question number in the right frame. The corresponding question should be displayed in the left frame.Insted when i click it, it only gets appended..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inter Frame communication in quiz application
 
Similar Threads
easy to use backend for my web project
Open Source application
The 34 Languages of McDonald's
What is the output for First Snippet and Second Snippet?
Automatically generate a JSP file in another active JSP page