@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String whoParam = req.getParameter("who"); String whatParam = req.getParameter("what"); System.out.println("whatParam = " + whatParam); System.out.println("whoParam = " + whoParam); if (whoParam == null || whatParam == null) { throw new HTTPException(HttpServletResponse.SC_BAD_REQUEST); } Prediction prediction = new Prediction(); prediction.setWho(whoParam); prediction.setWhat(whatParam); int id = predictions.addPrediction(prediction); String msg = "Prediction " + id + " Created.\n"; sendResponse(resp, predictions.toXML(msg), false); }
// POST /predictions2 // HTTP body should contain two keys, one for the predictor ("who") and // another for the prediction ("what"). public void doPost(HttpServletRequest request, HttpServletResponse response) { String who = request.getParameter("who"); String what = request.getParameter("what"); // Are the data to create a new prediction present? if (who == null || what == null) throw new HTTPException(HttpServletResponse.SC_BAD_REQUEST); // Create a Prediction. Prediction prediction = new Prediction(); prediction.setWho(who); prediction.setWhat(what); // Save the ID of the newly created Prediction. int id = predictions.addPrediction(prediction); // Generate the confirmation message. String msg = "Prediction " + id + " created.\n"; sendResponse(response, predictions.toXML(msg), false); }