/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String forward = ""; String action = request.getParameter("action"); if (action.equalsIgnoreCase("listar")) { forward = "/tanque/index.jsp"; request.setAttribute("tanque", dao.getAllTanque()); RequestDispatcher view = request.getRequestDispatcher(forward); view.forward(request, response); } else if (action.equalsIgnoreCase("create")) { forward = "/tanque/crear.jsp"; RequestDispatcher view = request.getRequestDispatcher(forward); view.forward(request, response); } else if (action.equalsIgnoreCase("edit")) { String userId = request.getParameter("userId"); tanque objtanque = dao.getUserById(userId); request.setAttribute("tanque", objtanque); forward = "/tanque/editar.jsp"; RequestDispatcher view = request.getRequestDispatcher(forward); view.forward(request, response); } else if (action.equalsIgnoreCase("delete")) { Integer userId = Integer.parseInt(request.getParameter("tanqueId")); dao.deleteTanque(userId); HttpSession session = request.getSession(); session.setAttribute("exito", "Tus datos se Eliminaron correctamente"); forward = "/tanque/index.jsp"; request.setAttribute("tanque", dao.getAllTanque()); RequestDispatcher view = request.getRequestDispatcher(forward); view.forward(request, response); } }
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String forward = ""; String action = request.getParameter("action"); tanque tanque = new tanque(); if (action.equalsIgnoreCase("create")) { tanque.setNombre_tanque(request.getParameter("nombre_tanque")); tanque.setColor(request.getParameter("color")); tanque.setVolumen(Double.parseDouble(request.getParameter("volumen"))); dao.addTanque(tanque); HttpSession session = request.getSession(); session.setAttribute("exito", "Tus datos se registraron correctamente"); forward = "/tanque/index.jsp"; request.setAttribute("tanque", dao.getAllTanque()); RequestDispatcher view = request.getRequestDispatcher(forward); view.forward(request, response); } else if (action.equalsIgnoreCase("update")) { tanque.setId_tanque(Integer.parseInt(request.getParameter("id"))); tanque.setNombre_tanque(request.getParameter("nombre_tanque")); tanque.setColor(request.getParameter("color")); tanque.setVolumen(Double.parseDouble(request.getParameter("volumen"))); dao.updateTanque(tanque); HttpSession session1 = request.getSession(); session1.setAttribute("exito", "Tus datos se Editaron correctamente"); forward = "/tanque/index.jsp"; request.setAttribute("tanque", dao.getAllTanque()); RequestDispatcher view1 = request.getRequestDispatcher(forward); view1.forward(request, response); } }