Пример #1
0
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // Get Context and Session
    // ServletContext context = request.getServletContext();
    HttpSession session = request.getSession();
    // init variables needed to create quiz
    User user = (User) session.getAttribute("user");
    String creator = user.getUserName();
    String title = request.getParameter("title");
    if (title.equals("")) {
      RequestDispatcher dispatcher = request.getRequestDispatcher("QuizCreation.jsp?error=1");
      dispatcher.forward(request, response);
      return;
    }
    String description = request.getParameter("description");
    if (description.equals("")) {
      description = "No description provided by " + creator;
    }

    // String creator = "Danny"; //for testing
    boolean randomOrder = Boolean.valueOf(request.getParameter("randomOrder"));
    boolean multiPage = Boolean.valueOf(request.getParameter("multiPage"));
    boolean immediateFeedback = Boolean.valueOf(request.getParameter("immediateFeedback"));
    boolean canPractice = Boolean.valueOf(request.getParameter("canPractice"));
    Quiz dup = QuizSite.getSite().getQuiz(SHAHasher.hash(title));
    if (dup != null) {
      RequestDispatcher dispatcher = request.getRequestDispatcher("QuizCreation.jsp?error=1");
      dispatcher.forward(request, response);
    } else {
      // Create Quiz
      try {
        quiz =
            Quiz.createQuiz(
                title,
                description,
                creator,
                randomOrder,
                multiPage,
                immediateFeedback,
                canPractice);
        session.setAttribute("quizBeingCreated", quiz);
        RequestDispatcher dispatcher = request.getRequestDispatcher("ChooseQuestionType.jsp");
        dispatcher.forward(request, response);
      } catch (SQLException e) {
        e.printStackTrace();
        RequestDispatcher dispatcher = request.getRequestDispatcher("Error.html");
        dispatcher.forward(request, response);
      }
    }
  }
Пример #2
0
 /** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
 protected void doGet(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   QuizSite qs = QuizSite.getSite();
   String quizId = request.getParameter("id");
   Quiz q = qs.getQuiz(quizId);
   request.getSession().setAttribute("quizBeingTaken", q);
   List<Integer> questionsRemaining = new ArrayList<Integer>();
   Iterator<Question> iter = q.getQuestions().iterator();
   while (iter.hasNext()) {
     questionsRemaining.add(iter.next().getId());
   }
   if (request.getParameterMap().containsKey("practiceMode")
       && Integer.parseInt(request.getParameter("practiceMode")) == 1) {
     request.getSession().setAttribute("practiceMode", 1);
   } else {
     request.getSession().setAttribute("practiceMode", 0);
   }
   request.getSession().setAttribute("questionsRemaining", questionsRemaining);
   request.getSession().setAttribute("quizPageNum", 0);
   request.getSession().setAttribute("score", 0.0);
   request.getSession().setAttribute("startTime", System.currentTimeMillis());
   RequestDispatcher dispatcher = request.getRequestDispatcher("TakeQuiz.jsp");
   dispatcher.forward(request, response);
 }