• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Inter Frame communication in quiz application

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
reply
    Bookmark Topic Watch Topic
  • New Topic