package jp.ac.kcska.questionsystem.katsuta; import java.io.IOException; import java.util.ArrayList; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import jp.ac.kcska.questionsystem.Mst_choiceVo; import jp.ac.kcska.questionsystem.Mst_questionVo; /** * Servlet implementation class answer */ @WebServlet("/answer") public class answer extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public answer() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse * response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse * response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub HttpSession session = request.getSession(); ArrayList list = (ArrayList) session .getAttribute("choicelist"); int c = (int) session.getAttribute("counter"); ArrayList list2=(ArrayList) session.getAttribute("questionVo"); String[] selectchoice = request.getParameterValues("anwser"); int n=(int)session.getAttribute("questionnumber"); int end = 0; if (c == 1) { for (Mst_choiceVo vo : list) { for (int i = 0; i < selectchoice.length; i++) { if (selectchoice[i].equals(vo.getId())) { if (vo.getAnswerflag() == 1) { end = 1; } } } } } else { int e = 0; for (Mst_choiceVo vo : list) { for (int i = 0; i < selectchoice.length; i++) { if (selectchoice[i].equals(vo.getId())) { if (vo.getAnswerflag() == 1) { end = 1; e++; } } } } if (e == c) { end = 0; } } ArrayList answer=new ArrayList(); answer.add(end); session.setAttribute("answer", answer); if(list2.size()==(n+1)){ RequestDispatcher dispatch = request .getRequestDispatcher("ResultServlet"); dispatch.forward(request, response); } RequestDispatcher dispatch = request .getRequestDispatcher("QuestionServlet"); dispatch.forward(request, response); } }