コード例 #1
0
ファイル: QuizManager.java プロジェクト: ataki/Quizzically
 private List<Quiz> convertToList(ResultSet r) throws SQLException {
   List<Quiz> result = new ArrayList<Quiz>();
   while (r.next()) {
     result.add(Quiz.fetch(r.getInt("id")));
   }
   return result;
 }
コード例 #2
0
ファイル: CreateServlet.java プロジェクト: ataki/Quizzically
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // if no session , redirect to login
    User user = (User) request.getSession().getAttribute("user");

    String quizName = request.getParameter("quiz-name");
    String quizDescription = request.getParameter("quiz-description");
    String quizCategory = request.getParameter("quiz-category");
    boolean immediate_feedback =
        request.getParameter("immediate-correction").equals("yes") ? true : false;
    boolean randomness = request.getParameter("order").equals("yes") ? false : true;
    boolean singlePage = request.getParameter("quiz-display").equals("one") ? true : false;
    // Push the quiz data into database (quiz name?), numQuestions? category? remove question?

    int dummyCategory_id = 0;
    // TODO: Create quizCategory enum, tags
    RequestDispatcher dispatch;
    List<BaseQuestion> questions = new ArrayList<BaseQuestion>();
    int returnValue = populateQuestions(request, singlePage, questions);

    if (returnValue == 0) {
      int points = 0;
      for (BaseQuestion q : questions) points += q.points();
      Quiz quiz =
          Quiz.insert(
              user.getId(),
              quizName,
              quizDescription,
              dummyCategory_id,
              randomness,
              immediate_feedback,
              singlePage,
              points,
              questions);
      if (quiz != null)
        dispatch = request.getRequestDispatcher("quiz-summary.jsp?quizId=" + quiz.getId());
      else dispatch = request.getRequestDispatcher("404.html");
    } else {
      dispatch = request.getRequestDispatcher("quiz-create.html?errorId=" + returnValue);
    }

    dispatch.forward(request, response);
  }