gpo
02-07-2007, 01:44 AM
I 've got a sample multiple choice form which I want to that processes the answers and returns a web page with the results of the test via servlet.
I can process the answers part,but how do you display the result ie if you get 60% of the answers its a pass ?
Part code of the form.
<form action=".../servlet/service" method="get">
Question 5:To which address class does the IP address 126.11.4.3 belong?
<td>
<input type="radio" name="q17_choose1" id="q17" value="Class A">
<label for="Class A">Class A</label> <br>
<input type="radio" name="q17_choose1" id="q17" value="Class B">
<label for="Class B">Class B</label> <br>
<input type="radio" name="q17_choose1" id="q17" value="Class c">
<label for="Class c">Class c</label> <br>
</td>
</table>
</td>
<input type="submit" value="Submit">
</td>
</tr>
</table>
</form>
The servlet process side...
part code.
public void doGet (HttpServletRequest request,
HttpServletResponse response
)throws IOException, ServletException {
// returns an enumeration of all the parameter names
Enumeration aEnumeration = request.getParameterNames();
String parameterName;
String value;
response.setContentType("text/html");
PrintWriter aPW = response.getWriter();
aPW.println( "<HTML><BODY>" );
while ( aEnumeration.hasMoreElements() ) {
parameterName = ( String )aEnumeration.nextElement();
value = request.getParameter( parameterName );
aPW.println( parameterName + " = " + value + "<BR>" );
}
aPW.println( "</BODY></HTML>" );
}
I can process the answers part,but how do you display the result ie if you get 60% of the answers its a pass ?
Part code of the form.
<form action=".../servlet/service" method="get">
Question 5:To which address class does the IP address 126.11.4.3 belong?
<td>
<input type="radio" name="q17_choose1" id="q17" value="Class A">
<label for="Class A">Class A</label> <br>
<input type="radio" name="q17_choose1" id="q17" value="Class B">
<label for="Class B">Class B</label> <br>
<input type="radio" name="q17_choose1" id="q17" value="Class c">
<label for="Class c">Class c</label> <br>
</td>
</table>
</td>
<input type="submit" value="Submit">
</td>
</tr>
</table>
</form>
The servlet process side...
part code.
public void doGet (HttpServletRequest request,
HttpServletResponse response
)throws IOException, ServletException {
// returns an enumeration of all the parameter names
Enumeration aEnumeration = request.getParameterNames();
String parameterName;
String value;
response.setContentType("text/html");
PrintWriter aPW = response.getWriter();
aPW.println( "<HTML><BODY>" );
while ( aEnumeration.hasMoreElements() ) {
parameterName = ( String )aEnumeration.nextElement();
value = request.getParameter( parameterName );
aPW.println( parameterName + " = " + value + "<BR>" );
}
aPW.println( "</BODY></HTML>" );
}