I have a .jsp file that should tell the user the result of their exam.
This is the WebController.java class that works out what a person gave as their answer and then adds either 0 or 1 depending on if their answer is wrong or right.
@RequestMapping(value = "/results", method = RequestMethod.POST)
public String results(Model model, HttpSession session, HttpServletRequest request,
HttpServletResponse response){
String radio = request.getParameter("radios1");
request.setAttribute("total", total);
model.addAttribute("total", total);
if (radio.equals("int")){
total = total + 0;
}
else if (radio.equals("Enum")){
total = total + 0;
}
else if (radio.equals("integer")){
total = total + 0;
}
else if (radio.equals("Integer")){
total = total + 1;
}
return "results";
}
I would like to print the "total" variable onto the jsp page so it displays in the browser. So the idea is the user will instantly be able to see what they got in their test.
Also can this work the same way in reverse? e.g. in the code above can the java class get the parameter "radios1" which is located inside a form in a jsp class?
<p>Good day <%= session.getAttribute("uname") %> </p>
<p>For question 1 you chose <%= session.getAttribute("q1") %> </p>
<p>For question 2 you chose <%= session.getAttribute("q2") %> </p>
<p>For question 3 you chose <%= session.getAttribute("q3") %> </p>
<p>For question 4 you chose <%= session.getAttribute("q4") %> </p>
<section>
<p>Total score: ${requestScope.total}</p>
<p>Total score: ${total}</p>
</section>