Click to See Complete Forum and Search --> : Any help on this servlet that processes the answers


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>" );
}

Xeel
02-07-2007, 03:43 AM
didnt understand the question, you mean how you know the answering percentage?

If your questions are all of the same value just divide 100 by the number of you questions and then calculate the percentage in your servlet. If they are of different value - use a hidden fields for ex. putting your percentage into "value" attribute to send them to the servlet together with the answers.

Then in your servet you can do whatever you want with these numbers...

If i didnt answer your question, try to reformulate it ;)

gpo
02-07-2007, 11:35 AM
if I didn't make my question clear,here's it again...
I want to do this:write a servlet that processes the answers and returns a web page with the results of the test?