@RequestMapping("/jogo/comprarEnergia") public ModelAndView comprarEnergia( @RequestParam(value = "quantidade", required = false) String quantidade) throws ServletException, IOException { Map<String, Object> myModel = new HashMap<String, Object>(); try { myModel.put( "result", (new JSONObject(service.comprarEnergia(Integer.parseInt(quantidade)))).toString()); } catch (NumberFormatException e) { myModel.put("result", (new JSONObject(service.comprarEnergia())).toString()); } return new ModelAndView("servico.jsp", "model", myModel); }