public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int groupHomeworkID = 0; try { Map<String, String> requestParameters = Utilities.getParameters(request, "groupHomeworkID"); groupHomeworkID = Integer.parseInt(requestParameters.get("groupHomeworkID")); } catch (Exception e) { e.printStackTrace(); } boolean updateResult = groupHomeworkService.updateActualMarkingCompletion(groupHomeworkID); JSONObject responseObject = new JSONObject(); if (updateResult) { responseObject.put("result", "SUCCESS"); responseObject.put( "message", "Successfully updated actual marking completion date of homework."); } else { responseObject.put("result", "FAILURE"); responseObject.put("message", "Failed to update actual marking completion date of homework."); } PrintWriter out = response.getWriter(); out.write(responseObject.toString()); }
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String rawStudentList = null; try { Map<String, String> requestParameters = Utilities.getParameters(request, "rawStudentList"); rawStudentList = requestParameters.get("rawStudentList"); } catch (Exception e) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); return; } JSONObject requestObject = new JSONObject(rawStudentList); JSONArray studentList = requestObject.getJSONArray("studentList"); JSONObject responseObject = new JSONObject(); for (int index = 0; index < studentList.length(); index++) { JSONObject student = studentList.getJSONObject(index); int studentID = student.getInt("studentID"); int userHomeworkID = student.getInt("userHomeworkID"); String homeworkGrade = student.getString("homeworkGrade"); if (!userHomeworkService.setHomeworkGrade(userHomeworkID, studentID, homeworkGrade)) { responseObject.put("result", GenericResult.FAILED.toString()); responseObject.put("message", "Failed to grade homework"); break; } else { responseObject.put("result", GenericResult.SUCCESS.toString()); responseObject.put("message", "Successfully graded homework"); } } PrintWriter out = response.getWriter(); out.write(responseObject.toString()); }