2012-10-21 4 views
0

일반 JSP-MsAccess connection.But을 기반으로 한 작은 퀴즈를 수행 할 웹 페이지를 개발 중입니다. 그러나 퀴즈를 실행할 때 질문에 답하면 모든 질문에 결과가 적용됩니다. 내 점수는 10 바로 그때 첫 번째 질문을 얻는 경우에 의미 내가 먼저 잘못된 답변을 얻을 경우 내 점수는 0 코드 : 일부 인덱스에서 즉JSP로 객관식 질문

를 사용하는

<%@ 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=" "; 
if(request.getParameter("correctAns")!=null) 
{ 
    ans=request.getParameter("correctAns").toString(); 
} 


Connection conn = null; 

Statement st = null; 

ResultSet rs = null; 

String id=request.getParameter("id"); 
System.out.println("id:"+id); 

int i=1; 

String s,g; 

int count=0; 

try { 

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
conn = DriverManager.getConnection("jdbc:odbc:qdsn"); 
rs = null; 

st = conn.createStatement(); 

//for(i=1;i<=2;i++) 
// { 
rs = st.executeQuery("select * from exam"); 

while(rs.next()) { 
%> 


<br/> 
<center> 

<table border="1" width="500px" bgcolor="pink" cellspacing="0" cellpadding="0"> 
    <tr> 
    <td width="100%"> 

<form name="form1"> 

<h2 align="center"><font color="red">Online Quiz Application</font></h2> 

<b>Select Correct Answer</b> 
     <table border="0" width="500px" cellspacing="2" cellpadding="4"> 
<tr> 

<td width="50%"> Question:</td> 
<input type="hidden" name="correctAns" value="<%=rs.getString(6)%>" /> 
<tr> 
<td><%= rs.getString("quest") %></td></tr> 
<tr> 
<td> 

1: <input type="radio" name="a" value= "QA" /></td> 
    <td><%= rs.getString("QA") %></td></tr> 
<tr> 
<td> 
2: <input type="radio" name="a" value="QB" /></td> 
<td><%= rs.getString("QB") %></td></tr> 

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

<tr> 
<td> 
4: <input type="radio" name="a" value="QD" /> </td> 
<td> <%= rs.getString("QD") %> </td></tr> 

<tr> 
<td> 
<center> 
    <input type="submit" value="Submit" name="submit"></center></td></tr> 
</table> 

</form> 
</td> 
    </tr> 
</table> 
</center> 
</body> 
<% g=request.getParameter("a"); 
%> 
<% 
if(g.equals(ans)){ 

count++; 
} 

%> 



<% 
}} 
// } 
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> 
+0

질문에 문제가 없습니다. – cherit

답변

1

업데이트 라디오 버튼 이름 맨 위 : 색인 변수를 선언하십시오.

<% int qNum = 0; %> 

페이지 중간에서 radio 필드 이름에 index 변수를 사용하십시오.

페이지 하단에서 색인 매개 변수를 검색하고 색인을 1 씩 늘리십시오.

<% g=request.getParameter("a"+qNum); 
    qNum++; 
    %>