コード例 #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
ファイル: RejectServlet.java プロジェクト: hspinks/cs108
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    int mesid = Integer.parseInt(request.getParameter("number"));
    String userName = request.getParameter("userName");
    QuizSite qs = QuizSite.getSite();
    User masterFriend = qs.getUser(userName);
    List<Integer> receivedMessages = masterFriend.getReceivedMessages();
    Messages mes = qs.getMessage(mesid);
    int type = mes.getType();

    if (type == 0) {
      Note nt = (Note) mes;
      try {
        Statement stmt = DBConnection.getConnection().createStatement();
        String sql = "update messages set viewed=1 where id=" + mesid;
        stmt.executeUpdate(sql);
        nt.setRead();
      } catch (SQLException e) {
        e.printStackTrace();
      }
    } else mes.remove();
    RequestDispatcher rd = request.getRequestDispatcher("MessageList.jsp");
    rd.forward(request, response);
  }