简体   繁体   中英

How to display the result in last page by collecting the results from previous jsp page?

I am creating a quiz application. Here, there are 5 jsp pages with 5 different quizes. I need to show all the results from QuizPage1.jsp, QuizPage2.jsp, QuizPage3.jsp, QuizPage4.jsp and QuizPage5.jsp to ResultPage.jsp.

I used session to get the answers from all jsp page. But, I need to display the result in last page as..

Question 1: Wrong Answer - Correct answer is ....... Question 2: Wrong Answer - Correct answer is ....... Question 3: Wrong Answer - Correct answer is ....... Question 4: Wrong Answer - Correct answer is ....... Question 5: Wrong Answer - Correct answer is .......

I used this scriplet in every jsp page by changing parameter..

     <%
     String s1=request.getParameter("grp");
     request.getSession().setAttribute("s1", s1);
     %>

Is there any solution?

Codes Refer- How to retrieve the values from previous jsp page to result page?

<%
String theAnswer1 = ...  
String userAnswer = (String)session.getAttribute("s1");
if (theAnswer.equals(userAnswer)) {
   out.println("Answer1 is correct - woohoo!");
} else {
   out.println("Question 1: Wrong answer - Correct answer is: " + theAnswer1)
}    
%>

Repeat the same pattern for answers 2, 3, 4 and 5.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM